local extension = Package:new("ysch4")
extension.extensionName = "ysch_Al"

local U = require "packages/utility/utility"

--将一些牌移出中央区（仍在弃牌堆内，但不计入中央区计算）
---@param player ServerPlayer @ 操作的角色
---@param card integer | integer[] | Card | Card[] @ 要移出的牌
---@param scope? integer @ 移出的历史范围，默认当回合
local RemoveCenterCards = function (player, card, scope)
    local room = player.room
    local banner = room:getBanner("@$CenterArea") or {}
    if #banner == 0 then return end
    local suffix_mapper = {
      [Player.HistoryGame] = "",
      [Player.HistoryRound] = "-round",
      [Player.HistoryTurn] = "-turn",
      [Player.HistoryPhase] = "-phase",
    }
    scope = scope or Player.HistoryTurn
    local ids = Card:getIdList(card)
    ids = table.filter(ids, function (id)
      return table.contains(banner, id)
    end)
    if #ids > 0 then
      for _, id in ipairs(ids) do
        table.removeOne(banner, id)
        room:setCardMark(Fk:getCardById(id), MarkEnum.RemoveCenterCards..suffix_mapper[scope], 1)
      end
      room.logic:trigger("fk.BeforeCenterAreaRemove", player, {ids = ids})
      room:setBanner("@$CenterArea", banner)
      room.logic:trigger("fk.AfterCenterAreaRemove", player, {ids = ids})
    end
end
--获得一名角色的明置手牌id列表
---@param player ServerPlayer | Player @ 目标角色
---@return integer[]
local GetShownCards = function (player)
    return table.filter(player:getCardIds("h"), function (id)
      return Fk:getCardById(id):getMark(MarkEnum.ShownCards) > 0 or
        table.find(MarkEnum.TempMarkSuffix, function (suffix)
          return Fk:getCardById(id):getMark(MarkEnum.ShownCards..suffix) > 0
        end)
    end)
end
local getAllCardNames = function(card_type, true_name)
    local all_names = {}
    local basics = {}
    local normalTricks = {}
    local delayedTricks = {}
    local equips = {}
    for _, card in ipairs(Fk.cards) do
        if card.package and not table.contains(Fk:currentRoom().disabled_packs, card.package.name) and not card.is_derived then
            if card.type == Card.TypeBasic then
                table.insertIfNeed(basics, true_name and card.trueName or card.name)
            elseif card.type == Card.TypeTrick and card.sub_type ~= Card.SubtypeDelayedTrick then
                table.insertIfNeed(normalTricks, true_name and card.trueName or card.name)
            elseif card.type == Card.TypeTrick and card.sub_type == Card.SubtypeDelayedTrick then
                table.insertIfNeed(delayedTricks, true_name and card.trueName or card.name)
            elseif card.type == Card.TypeEquip then
                table.insertIfNeed(equips, true_name and card.trueName or card.name)
            end
        end
    end
    if card_type:find("b") then
        table.insertTable(all_names, basics)
    end
    if card_type:find("t") then
        table.insertTable(all_names, normalTricks)
    end
    if card_type:find("d") then
        table.insertTable(all_names, delayedTricks)
    end
    if card_type:find("e") then
        table.insertTable(all_names, equips)
    end
    return all_names
end
---@param player ServerPlayer @ 目标角色
local DIYEnterHidden = function (player)
    local room = player.room
    room:sendLog({
      type = "#EnterHidden",
      from = player.id,
    })
    local skills = "hidden_skill&"
    room:setPlayerMark(player, "__hidden_general", player.general)
    for _, s in ipairs(Fk.generals[player.general]:getSkillNameList(true)) do
      if player:hasSkill(s, true) then
        skills = skills.."|-"..s
      end
    end
    if player.deputyGeneral ~= "" then
      room:setPlayerMark(player, "__hidden_deputy", player.deputyGeneral)
      for _, s in ipairs(Fk.generals[player.deputyGeneral]:getSkillNameList(true)) do
        if player:hasSkill(s, true) then
          skills = skills.."|-"..s
        end
      end
    end
    player.general = "hiddenone"
    player.gender = General.Male
    room:broadcastProperty(player, "gender")
    if player.deputyGeneral ~= "" then
      player.deputyGeneral = ""
    end
    player.kingdom = "jin"
    room:setPlayerMark(player, "__hidden_record",
    {
      maxHp = player.maxHp,
      hp = player.hp,
    })
    player.maxHp = 1
    player.hp = 1
    for _, property in ipairs({"general", "deputyGeneral", "kingdom", "maxHp", "hp"}) do
      room:broadcastProperty(player, property)
    end
    room:handleAddLoseSkills(player, skills, nil, false, true)
end

--添加英文到中文的翻译
Fk:loadTranslationTable{
    ["#EnterHidden"] = "%from 进入隐匿状态",
    ["ysch4"] = "亦书成花",--小包名
}

--[[
    铝包智慧，直接搬运封侯包，并且不用改命名（直接适配）

    多项转换技：项数大于2的转换技
    用名为rfenghou_switch的角色标记储存所有这类转换技
    标记格式为{技能名，当前项数，总项数，标记颜色}
    请在多项转换技的on_aquire中使用setSwitchState(player, skillName, 1, total)用于新建转换技
    changeSwitchState(player, skillName, add)用于增加或减少当前项数
    若从最后一项返回第一项，触发fk.RfenghouSwitchLoopback（周转）事件
    注意，请务必在技能on_lose调用removeSwitchSkill清除标记占用

    标记命名格式：
    @!rfenghou_ .. 颜色 .. 项数(1~9)，如 @!rfenghou_red1
    大于等于10项时，标记命名为 @!rfenghou_redx ，使用标记数量代表当前项
    注意，UI上标记数至多显示为999
--]]


--- 更新角色转换技的UI标记。
--- @param player ServerPlayer @ 目标角色
--- @param color string @ 标记颜色
--- @param old? integer @ 旧项数
--- @param new? integer @ 新项数
local refreshSwitchMark = function (player, color, old, new)
    if old then
        if old < 10 then
            player.room:setPlayerMark(player, "@!rfenghou_"..color..old, 0)
        else
            player.room:setPlayerMark(player, "@!rfenghou_"..color.."x", 0)
        end
    end
    if new then
        if new < 10 then
            player.room:setPlayerMark(player, "@!rfenghou_"..color..new, 1)
        else
            player.room:setPlayerMark(player, "@!rfenghou_"..color.."x", new)
        end
    end
end
  
--- 将多项转换技的当前项数增加1项
---@param player ServerPlayer @ 目标角色
---@param skillName string @ 转换技总项数
---@param add? boolean @ 是否为增加，写false则后退一项。默认增加
local changeSwitchState = function (player, skillName, add)
    if player.dead then return end
    local room = player.room
    local mark = player:getTableMark("rfenghou_switch")
    local skillIndex
    for i, v in ipairs(mark) do
        if v[1] == skillName then
            skillIndex = i
            break
        end
    end
    if skillIndex == nil then
        p("Warning:Cannot find the index of the switch skill ["..skillName.."]. Check if its mark have been illegally removed or not added")
        return
    end
    local oldIndex, total, color = mark[skillIndex][2], mark[skillIndex][3], mark[skillIndex][4]
    local newIndex, loopBack
    if add or (add == nil) then
        newIndex = oldIndex + 1
        if newIndex > total then
            loopBack = true
            newIndex = 1
        end
    else
        newIndex = oldIndex - 1
        if newIndex < 1 then
            newIndex = total
        end
    end
    mark[skillIndex][2] = newIndex
    room:setPlayerMark(player, "rfenghou_switch", mark)
    if color then
        refreshSwitchMark(player, color, oldIndex, newIndex)
    end
    -- 触发“周转”
    if loopBack then
        room.logic:trigger("fk.RfenghouSwitchLoopback", player, {skillName = skillName}, false)
    end
end
  
  --- 设置多项转换技的状态。也可用于新建多项转换技
  ---@param player ServerPlayer @ 目标角色
  ---@param skillName string @ 技能名
  ---@param index? integer @ 设置当前项数
  ---@param total? integer @ 转换技总项数
local setSwitchState = function (player, skillName, index, total)
    local mark = player:getTableMark("rfenghou_switch")
    local colors, oldIndex = {"red", "green", "yellow", "blue"}, nil
    local skillIndex -- 判断此转换技在该角色所有转换技的储存位置
    for i, v in ipairs(mark) do
        if v[1] == skillName then
            skillIndex = i
            break
        end
    end
    if skillIndex == nil then -- 找不到记录，则新建一个记录
        table.insert(mark, {skillName, index or 1, total or 3})
        skillIndex = #mark
        -- 为此转换技分配标记颜色
        local color = table.find(colors, function(c)
            return table.every(mark, function(v) return v[4] ~= c end)
        end)
        if color then
            mark[skillIndex][4] = color
        end
    else
        oldIndex = mark[skillIndex][2]
    end
    if index then
        mark[skillIndex][2] = index
    end
    if total then
        mark[skillIndex][3] = total
    end
    player.room:setPlayerMark(player, "rfenghou_switch", mark)
    if mark[skillIndex][4] then
        refreshSwitchMark(player, mark[skillIndex][4], oldIndex, index)
    end
end
  
  
--- 清除一个多项转换技
---@param player ServerPlayer @ 目标角色
---@param skillName string @ 技能名
local removeSwitchSkill = function (player, skillName)
    local mark = player:getTableMark("rfenghou_switch")
    local color, index
    for i, v in ipairs(mark) do
        if v[1] == skillName then
            if v[4] then
            color = v[4]
            index = v[2]
            end
            table.remove(mark, i)
            break
        end
    end
    player.room:setPlayerMark(player, "rfenghou_switch", mark)
    if color then
        refreshSwitchMark(player, color, index)
        -- 清除后可以把它分配的颜色转移给未分配颜色的技能，以后再说吧
    end
end
  
  
--- 获取多项转换技的当前项。若未记录，返回0
---@param player Player @ 目标角色
---@param skillName string @ 技能名
---@return integer
local getSwitchState = function (player, skillName)
    local mark = player:getTableMark("rfenghou_switch")
    for i, v in ipairs(mark) do
        if v[1] == skillName then
            return v[2]
        end
    end
    return 0
end

local huangwudie = General:new(extension, "ysch4__huangwudie", "shu", 4, 4, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__huangwudie"] = "黄舞蝶",
    ["#ysch4__huangwudie"] = "飞影踏风",
    ["designer:ysch4__huangwudie"] = "cyc",
    ["cv:ysch4__huangwudie"] = "隐匿",
    ["illustrator:ysch4__huangwudie"] = "佚名",
}
local lanfeng = fk.CreateTriggerSkill{
    name = "ysch4_lanfeng",
    anim_type = "offensive",
    events = {fk.TargetSpecified, fk.TargetConfirmed},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) and data.card.trueName == "slash" then
            if event == fk.TargetSpecified then
                return data.firstTarget
            else
                return true
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.map(data.tos,function (p) return p[1] end)
        table.insertIfNeed(targets,player.id)
        local tos = room:askForChoosePlayers(player, targets, 1, 1, "#ysch4_lanfeng-choose:::"..player:getMark("ysch4_lanfeng"), self.name, true)
        if #tos > 0 then
            self.cost_data = tos[1]
            return true
        end
    end,
    on_use =function (self, event, target, player, data)
        local room = player.room
        local target = room:getPlayerById(self.cost_data)
        U.swapCardsWithPile(target, target:getCardIds("h"), room:getNCards(player:getMark("ysch4_lanfeng")), self.name, "Top", false, player.id)
    end,
    on_acquire = function (self, player, is_start)
        local room = player.room
        if player:getMark("ysch4_lanfeng") == 0 then
            room:setPlayerMark(player,"ysch4_lanfeng",2)
        end
        room:setPlayerMark(player,"@ysch4_lanfeng",player:getMark("ysch4_lanfeng"))
    end,
    on_lose =function (self, player, is_death)
        local room = player.room
        room:setPlayerMark(player,"@ysch4_lanfeng",0)
    end,
}
huangwudie:addSkill(lanfeng)
local yunling = fk.CreateTriggerSkill{
    name = "ysch4_yunling",
    anim_type = "control",
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Start
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local card = Fk:cloneCard("slash")
        local card_skill = card.skill
        local choices = room:askForChoices(player,{"#ysch4_yunling1:::"..player:getAttackRange(),"#ysch4_yunling2:::"..card_skill:getMaxUseTime(player, Player.HistoryPhase, card, nil),"#ysch4_yunling3:::"..player:getMark("ysch4_lanfeng")},1,2,self.name,"#ysch4_yunling",true)
        if #choices > 0 then
            self.cost_data = choices
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local choices = table.map(self.cost_data,function(e) return e[15] end)
        if table.contains(choices,"1") then
            room:setPlayerMark(player,"@ysch4_yunling1",tostring(-1))
        else
            room:setPlayerMark(player,"@ysch4_yunling1","+"..tostring(#choices))
        end
        if table.contains(choices,"2") then
            room:setPlayerMark(player,"@ysch4_yunling2",tostring(-1))
        else
            room:setPlayerMark(player,"@ysch4_yunling2","+"..tostring(#choices))
        end
        local mark = player:getMark("ysch4_lanfeng")
        if table.contains(choices,"3") then
            room:setPlayerMark(player,self.name,-#choices)
            room:setPlayerMark(player,"ysch4_lanfeng",mark - 1)
        else
            room:setPlayerMark(player,self.name,#choices)
            room:setPlayerMark(player,"ysch4_lanfeng",mark + #choices)
        end
        room:setPlayerMark(player,"@ysch4_lanfeng",player:getMark("ysch4_lanfeng"))
    end,

    refresh_events = {fk.TurnStart},
    can_refresh = function (self, event, target, player, data)
        return target == player and player:getMark(self.name) ~= 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getMark("ysch4_lanfeng")
        room:setPlayerMark(player, "@ysch4_yunling1", 0)
        room:setPlayerMark(player, "@ysch4_yunling2", 0)
        if player:getMark(self.name) > 0 then
            room:setPlayerMark(player, "ysch4_lanfeng", mark - player:getMark(self.name))
        else
            room:setPlayerMark(player, "ysch4_lanfeng", mark + 1)
        end
        room:setPlayerMark(player,self.name,0)
        room:setPlayerMark(player,"@ysch4_lanfeng",player:getMark("ysch4_lanfeng"))
    end,
}
local yunling_attackrange = fk.CreateAttackRangeSkill{
    name = "#ysch4_yunling_attackrange",
    main_skill = yunling,
    correct_func = function (self, from, to)
        if type(from:getMark("@ysch4_yunling1")) == "string" then
            return tonumber(from:getMark("@ysch4_yunling1"))
        end
    end,
}
local yunling_targetmod = fk.CreateTargetModSkill{
    name = "#ysch4__yunling_targetmod",
    main_skill = yunling,
    residue_func = function(self, player, skill, scope)
        if skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
            if type(player:getMark("@ysch4_yunling2")) == "string" then
                return tonumber(player:getMark("@ysch4_yunling2"))
            end
        end
    end,
}
yunling:addRelatedSkill(yunling_attackrange)
yunling:addRelatedSkill(yunling_targetmod)
huangwudie:addSkill(yunling)
Fk:loadTranslationTable{
    ["ysch4_lanfeng"] = "岚锋",
    [":ysch4_lanfeng"] = "你指定或成为【杀】的目标后，你可以令你或目标用手牌替换牌堆顶的「<font color='#ff9244'>2</font>」张牌。",
    ["#ysch4_lanfeng-choose"] = "是否发动 岚锋，令你或目标用手牌替换牌堆顶的「%arg」张牌",
    ["@ysch4_lanfeng"] = "岚锋",
    ["ysch4_yunling"] = "云翎",
    [":ysch4_yunling"] = "准备阶段，你可以令以下一至二项数值-1，其余项+<font color='#ff9244'>X</font>，直到你下回合开始：1.攻击范围；2.使用【杀】的次数；3.「」内的数字。（<font color='#ff9244'>X</font>为你本次选择的项数）",
    ["#ysch4_yunling"] = "是否发动 云翎，令以下一至二项数值-1，其他数值+选择项数直至你下回合开始",
    ["#ysch4_yunling1"] = "攻击范围（%arg）",
    ["#ysch4_yunling2"] = "使用【杀】的次数（%arg）",
    ["#ysch4_yunling3"] = "「」内的数字（%arg）",
    ["@ysch4_yunling1"] = "攻击范围",
    ["@ysch4_yunling2"] = "出杀上限",

    ["$ysch4_lanfeng1"] = "以虚虚实实之箭，溃浩浩汤汤之敌！",
    ["$ysch4_lanfeng2"] = "清风拂面过，寒芒暗诛心！",
    ["$ysch4_yunling1"] = "隐身于，山岚之境。",
    ["$ysch4_yunling2"] = "藏匿于，雾霭之心。",
}

local zhouxuan = General:new(extension, "ysch4__zhouxuan", "wei", 2, 2, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__zhouxuan"] = "周宣",
    ["#ysch4__zhouxuan"] = "大梦仙尊",
    ["designer:ysch4__zhouxuan"] = "cyc",
    ["cv:ysch4__zhouxuan"] = "官方",
    ["illustrator:ysch4__zhouxuan"] = "匠人绘",
}
local huangjue = fk.CreateViewAsSkill{
    name = "ysch4_huangjue",
    anim_type = "support",
    prompt = "#ysch4_huangjue-prompt",
    mute = true,
    frequency = Skill.Wake,
    can_wake = function (self, event, target, player, data)
        return true
    end,
    card_filter = Util.FalseFunc,
    card_num = 0,
    pattern = "peach",
    view_as = function (self, cards, player)
        local c = Fk:cloneCard("peach")
        c.skillName = self.name
        return c
    end,
    before_use = function (self, player, use)
        local room = player.room
        room:notifySkillInvoked(player,self.name,"support")
        player:broadcastSkillInvoke(self.name)
        local skills = table.map(table.filter(player.player_skills, function (s)
            return s:isPlayerSkill(player) and not s.name:startsWith("#") and s.visible
        end), Util.NameMapper)
        if #skills > 0 then
            local skill = room:askForChoice(player, skills, self.name, "#ysch4_huangjue-lose")
            room:handleAddLoseSkills(player, "-"..skill)
            room:setPlayerMark(player,"@@ysch4_huangjue",0)
            player:setSkillUseHistory("#ysch4_huangjue_trigger",0,Player.HistoryGame)
            player:setSkillUseHistory(self.name,0,Player.HistoryGame)
        end
    end,
    enabled_at_play = function (self, player)
        local skills = table.map(table.filter(player.player_skills, function (s)
            return s:isPlayerSkill(player) and not s.name:startsWith("#") and s.visible
        end), Util.NameMapper)
        return #skills > 0 and player:getMark("@@ysch4_huangjue") ~= 0
    end,
    enabled_at_response = function (self, player, response)
        local skills = table.map(table.filter(player.player_skills, function (s)
            return s:isPlayerSkill(player) and not s.name:startsWith("#") and s.visible
        end), Util.NameMapper)
        return not response and #skills > 0 and player:getMark("@@ysch4_huangjue") ~= 0
    end,
}
local zhuoming_buff = fk.CreateTriggerSkill{
    name = "#steam__zhuoming_buff",
    mute = true,
    frequency = Skill.Compulsory,
    events = {fk.BeforeDrawCard},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and player:getMark("steam__zhuoming1") > 0 and target==player
    end,
    on_use = function(self, event, target, player, data)
        data.n = data.n * 2
    end,
}
Fk:addSkill(zhuoming_buff)
local huangjue_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_huangjue_trigger",
    anim_type = "support",
    mute = true,
    frequency = Skill.Wake,
    main_skill = huangjue,
    events = {fk.PreTurnStart},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill("ysch4_huangjue") and player:usedSkillTimes(self.name, Player.HistoryGame) == 0 and player:getMark("@@ysch4_huangjue") == 0
    end,
    can_wake = function (self, event, target, player, data)
        return true
    end,
    on_cost =function (self, event, target, player, data)
        local room = player.room
        local skills = {}
        for name, skill in pairs(Fk.skills) do
            if name ~= "ysch4_huangjue" and skill ~= self and not skill.attached_equip and not name:endsWith("&") and not name:startsWith("#") and
                skill.frequency == Skill.Wake and not player:hasSkill(name) then
                if Fk:translate(name, "zh_CN") == "震莽" then
                    if name == "steam0__zhenmang" then
                        table.insertIfNeed(skills, name)
                    end
                else
                    table.insertIfNeed(skills, name)
                end
            end
        end
        if #skills > 0 then
            local skill = room:askForChoice(player,table.random(skills,3),self.name,"#ysch4_huangjue-choices",true)
            self.cost_data = skill
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,self.name,"big")
        player:setSkillUseHistory(self.name,1,Player.HistoryGame)
        player:setSkillUseHistory("ysch4_huangjue",1,Player.HistoryGame)
        player:broadcastSkillInvoke("ysch4_huangjue")
        room:setPlayerMark(player,"@@ysch4_huangjue",1)
        room:handleAddLoseSkills(player,self.cost_data)
        player:gainAnExtraTurn()
    end,

    refresh_events = {fk.EventPhaseChanging,fk.BeforeTriggerSkillUse},
    can_refresh = function(self, event, target, player, data)
        if event == fk.EventPhaseChanging then
            return target == player and player:getCurrentExtraTurnReason() == self.name
        else
            return data.skill.frequency == Skill.Wake and (not table.contains({self.name,"ysch4_huangjue"},data.skill.name) or player ~= target)
        end
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        if event == fk.EventPhaseChanging then
            local excludePhases = { Player.Judge, Player.Draw, Player.Discard }
            for _, phase in ipairs(excludePhases) do
                table.removeOne(player.phases, phase)
            end
        else
            room:setPlayerMark(player,"@@ysch4_huangjue",0)
            player:setSkillUseHistory(self.name,0,Player.HistoryGame)
            player:setSkillUseHistory("ysch4_huangjue",0,Player.HistoryGame)
        end
    end,
}
huangjue:addRelatedSkill(huangjue_trigger)
local aohai = fk.CreateActiveSkill{
    name = "ysch4_aohai",
    anim_type = "support",
    card_num = 4,
    card_filter = function (self, to_select, selected)
        if #selected < 4 then
          local c = Fk:getCardById(to_select)
          if c.suit ~= Card.NoSuit and not Self:prohibitDiscard(c) then
            return #selected == 0 or table.every(selected, function (id)
              return Fk:getCardById(id).suit ~= c.suit
            end)
          end
        end
    end,
    target_num = 1,
    target_filter = function(self, to_select, selected, selected_cards)
        return true
    end,
    on_use = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])
        room:throwCard(effect.cards, self.name, from, from)

        room:notifySkillInvoked(from,"ysch4_limited_huishi","big")
        local wakeSkills = {}
        wakeSkills = table.map(table.filter(to.player_skills, function(s)
            return s.frequency == Skill.Wake and to:usedSkillTimes(s.name, Player.HistoryGame) < 1
        end), function(skill)
            return skill.name
        end)

        if #wakeSkills > 0 then
            for index, value in ipairs(wakeSkills) do
                room:addTableMarkIfNeed(to, "@[:]ysch4_limited_huishi", value)
                room:addTableMarkIfNeed(to, MarkEnum.StraightToWake, value)
            end
        else
            to:drawCards(4, self.name)
        end

        room:changeMaxHp(from, -2)
    end,
}
local aohai_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_aohai_trigger",
    main_skill = aohai,
    mute = true,
    events = {fk.EventPhaseStart, fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill("ysch4_aohai") and target == player then
            if event == fk.DamageInflicted then return true end
            return player.phase == Player.Start
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,self.main_skill.name,"support")
        room:changeMaxHp(player, 1)
        player:drawCards(1,self.name)
    end,
}
local limitedHuishi = fk.CreateActiveSkill{
    name = "ysch4_limited_huishi",
    anim_type = "support",
    frequency = Skill.Limited,
    target_num = 1,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards)
        return true
    end,
    on_use = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.tos[1])

        local wakeSkills = {}
        wakeSkills = table.map(table.filter(to.player_skills, function(s)
            return s.frequency == Skill.Wake and to:usedSkillTimes(s.name, Player.HistoryGame) < 1
        end), function(skill)
            return skill.name
        end)

        if #wakeSkills > 0 then
            for index, value in ipairs(wakeSkills) do
                room:addTableMarkIfNeed(to, "@[:]ysch4_limited_huishi", value)
                room:addTableMarkIfNeed(to, MarkEnum.StraightToWake, value)
            end
        else
            to:drawCards(4, self.name)
        end

        room:changeMaxHp(from, -2)
    end,
}
local limitedHuishiClear = fk.CreateTriggerSkill{
    name = "#ysch4__limited_huishi-clear",
    refresh_events = {fk.BeforeTriggerSkillUse},
    can_refresh = function(self, event, target, player, data)
        return
            target == player and
            data.willUse and
            data.skill.frequency == Skill.Wake and
            type(player:getMark("@[:]ysch4_limited_huishi")) == "table" and
            table.contains(player:getMark("@[:]ysch4_limited_huishi"), data.skill.name)
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        room:removeTableMark(player, "@[:]ysch4_limited_huishi", data.skill.name)
        room:removeTableMark(player, MarkEnum.StraightToWake, data.skill.name)
    end,
}
zhouxuan:addSkill(huangjue)
aohai:addRelatedSkill(limitedHuishiClear)
aohai:addRelatedSkill(aohai_trigger)
zhouxuan:addSkill(aohai)
limitedHuishi:addRelatedSkill(limitedHuishiClear)
zhouxuan:addRelatedSkill(limitedHuishi)
if not Fk.skills["ex__yingzi"] then
    local ex__yingzi = fk.CreateTriggerSkill{
        name = "ex__yingzi",
        anim_type = "drawcard",
        frequency = Skill.Compulsory,
        events = {fk.DrawNCards},
        on_use = function(self, event, target, player, data)
          data.n = data.n + 1
        end,
    }
    local ex__yingzi_maxcards = fk.CreateMaxCardsSkill{
        name = "#ex__yingzi_maxcards",
        main_skill = ex__yingzi,
        fixed_func = function(self, player)
          if player:hasShownSkill(ex__yingzi) then
            return player.maxHp
          end
        end
    }
    ex__yingzi:addRelatedSkill(ex__yingzi_maxcards)
    Fk:addSkill(ex__yingzi)
    Fk:loadTranslationTable{
        ["ex__yingzi"] = "英姿",
        [":ex__yingzi"] = "锁定技，摸牌阶段，你多摸一张牌；你的手牌上限等同于你的体力上限。",
    }
end
if not Fk.skills["yinghun"] then
    local yinghun = fk.CreateTriggerSkill{
        name = "yinghun",
        anim_type = "drawcard",
        mute = true,
        events = {fk.EventPhaseStart},
        can_trigger = function(self, event, target, player, data)
          return target == player and player:hasSkill(self) and player.phase == Player.Start and player:isWounded()
        end,
        on_cost = function(self, event, target, player, data)
          local to = player.room:askForChoosePlayers(player, table.map(player.room:getOtherPlayers(player, false), Util.IdMapper),
          1, 1, "#yinghun-choose:::"..player:getLostHp(), self.name, true)
          if #to > 0 then
            self.cost_data = {tos = to}
            return true
          end
        end,
        on_use = function(self, event, target, player, data)
          local room = player.room
          local to = room:getPlayerById(self.cost_data.tos[1])
          local n = player:getLostHp()
          local choices = {"#yinghun-draw:::" .. n,  "#yinghun-discard:::" .. n}
          local choice = (n == 1) and choices[1] or room:askForChoice(player, choices, self.name)
          if choice:startsWith("#yinghun-draw") then
            player:broadcastSkillInvoke(self.name, 1)
            room:notifySkillInvoked(player, self.name, "support", {to.id})
            to:drawCards(n, self.name)
            room:askForDiscard(to, 1, 1, true, self.name, false)
          else
            player:broadcastSkillInvoke(self.name, 2)
            room:notifySkillInvoked(player, self.name, "control", {to.id})
            to:drawCards(1, self.name)
            room:askForDiscard(to, n, n, true, self.name, false)
          end
        end,
    }
    Fk:addSkill(yinghun)
    Fk:loadTranslationTable{
        ["yinghun"] = "英魂",
    [":yinghun"] = "准备阶段，若你已受伤，你可以选择一名其他角色并选择一项：1.令其摸X张牌，然后弃置一张牌；2.令其摸一张牌，然后弃置X张牌（X为你已损失的体力值）。",
    ["#yinghun-choose"] = "英魂：你可以令一名其他角色：摸%arg张牌然后弃置一张牌，或摸一张牌然后弃置%arg张牌",
    ["#yinghun-draw"] = "摸%arg张牌，弃置1张牌",
    ["#yinghun-discard"] = "摸1张牌，弃置%arg张牌",
    }
end
if not Fk.skills["ex__jianxiong"] then
    local ex__jianxiong = fk.CreateTriggerSkill{
        name = "ex__jianxiong",
        anim_type = "masochism",
        events = {fk.Damaged},
        on_use = function(self, event, target, player, data)
          if data.card and U.hasFullRealCard(player.room, data.card) then
            player.room:obtainCard(player.id, data.card, true, fk.ReasonJustMove)
          end
          player:drawCards(1, self.name)
        end,
    }
    Fk:addSkill(ex__jianxiong)
    Fk:loadTranslationTable{
        ["ex__jianxiong"] = "奸雄",
        [":ex__jianxiong"] = "当你受到伤害后，你可以获得对你造成伤害的牌并摸一张牌。",
    }
end
if not Fk.skills["ex__rende"] then
    local ex__rende = fk.CreateActiveSkill{
        name = "ex__rende",
        anim_type = "support",
        min_card_num = 1,
        target_num = 1,
        prompt = "#ex__rende",
        card_filter = function(self, to_select, selected)
          return table.contains(Self:getCardIds("h"), to_select)
        end,
        target_filter = function(self, to_select, selected)
          return #selected == 0 and to_select ~= Self.id and Fk:currentRoom():getPlayerById(to_select):getMark("_ex__rende-phase") == 0
        end,
        on_use = function(self, room, effect)
          local target = room:getPlayerById(effect.tos[1])
          local player = room:getPlayerById(effect.from)
          local cards = effect.cards
          local marks = player:getMark("_rende_cards-phase")
          room:moveCardTo(cards, Player.Hand, target, fk.ReasonGive, self.name, nil, false)
          room:addPlayerMark(player, "_rende_cards-phase", #cards)
          room:setPlayerMark(target, "_ex__rende-phase", 1)
          if marks < 2 and marks + #cards >= 2 then
            cards = U.getUniversalCards(room, "b", false)
            local use = U.askForUseRealCard(room, player, cards, nil, self.name, "#ex__rende-ask",
              {expand_pile = cards, bypass_times = false, extraUse = false}, true, true)
            if use then
              use = {
                card = Fk:cloneCard(use.card.name),
                from = player.id,
                tos = use.tos,
              }
              use.card.skillName = self.name
              room:useCard(use)
            end
          end
        end,
    }
    Fk:addSkill(ex__rende)
    Fk:loadTranslationTable{
        ["ex__rende"] = "仁德",
        [":ex__rende"] = "出牌阶段每名角色限一次，你可以将任意张手牌交给一名其他角色，每阶段你以此法给出第二张牌时，你可以视为使用一张基本牌。",
        ["#ex__rende"] = "仁德：将任意张手牌交给一名角色，若此阶段交出达到两张，你可以视为使用一张基本牌",
        ["#ex__rende-ask"] = "仁德：你可视为使用一张基本牌",
    }
end
if not Fk.skills["ex__zhiheng"] then
    local ex__zhiheng = fk.CreateActiveSkill{
        name = "ex__zhiheng",
        anim_type = "drawcard",
        min_card_num = 1,
        target_num = 0,
        prompt = "#ex__zhiheng",
        can_use = function(self, player)
            return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
        end,
        card_filter = function(self, to_select, selected)
            return not Self:prohibitDiscard(Fk:getCardById(to_select))
        end,
        on_use = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            local hand = player:getCardIds(Player.Hand)
            local more = #hand > 0
            for _, id in ipairs(hand) do
                if not table.contains(effect.cards, id) then
                more = false
                break
                end
            end
            room:throwCard(effect.cards, self.name, player, player)
            if not player.dead then
                room:drawCards(player, #effect.cards + (more and 1 or 0), self.name)
            end
        end
    }
    Fk:addSkill(ex__zhiheng)
    Fk:loadTranslationTable{
        ["ex__zhiheng"] = "制衡",
        [":ex__zhiheng"] = "出牌阶段限一次，你可以弃置任意张牌并摸等量的牌。若你以此法弃置了所有的手牌，你多摸一张牌。",
        ["#ex__zhiheng"] = "制衡：你可以弃置任意张牌并摸等量的牌，若弃置了所有的手牌，多摸一张牌",
    }
end
if not Fk.skills["gongxin"] then
    local gongxin = fk.CreateActiveSkill{
        name = "gongxin",
        anim_type = "control",
        prompt = "#gongxin-active",
        target_num = 1,
        card_num = 0,
        can_use = function(self, player)
            return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
        end,
        card_filter = Util.FalseFunc,
        target_filter = function(self, to_select, selected, _, _, _, player)
            return #selected == 0 and to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
        end,
        on_use = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            local target = room:getPlayerById(effect.tos[1])
            local cards = target.player_cards[Player.Hand]
            local hearts = table.filter(cards, function (id) return Fk:getCardById(id).suit == Card.Heart end)
            local ids, choice = U.askforChooseCardsAndChoice(player, hearts, {"gongxin_discard", "gongxin_put"},
            self.name, "#gongxin-view::" .. target.id, {"Cancel"}, 1, 1, cards)
            if choice == "gongxin_discard" then
                room:throwCard(ids, self.name, target, player)
            elseif choice == "gongxin_put" then
                room:moveCardTo(ids, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
            end
        end,
    }
    Fk:addSkill(gongxin)
    Fk:loadTranslationTable{
        ["gongxin"] = "攻心",
        [":gongxin"] = "出牌阶段限一次，你可以观看一名其他角色的手牌并可以展示其中的一张<font color='red'>♥</font>牌，"..
        "选择：1. 弃置此牌；2. 将此牌置于牌堆顶。",
        ["#gongxin-active"] = "发动 攻心，观看一名其他角色的手牌",
        ["#gongxin-view"] = "攻心：观看%dest的手牌",
        ["gongxin_discard"] = "弃置此牌",
        ["gongxin_put"] = "将此牌置于牌堆顶",
    }
end
if not Fk.skills["cunmu"] then
    local cunmu = fk.CreateTriggerSkill{
        name = "cunmu",
        events = {fk.BeforeDrawCard},
        anim_type = "negative",
        frequency = Skill.Compulsory,
        on_use = function(self, event, target, player, data)
          data.fromPlace = "bottom"
        end,
    }
    Fk:addSkill(cunmu)
    Fk:loadTranslationTable{
        ["cunmu"] = "寸目",
        [":cunmu"] = "锁定技，当你摸牌时，改为从牌堆底摸牌。",
    }
end
if not Fk.skills["jueqing"] then
    local jueqing = fk.CreateTriggerSkill{
        name = "jueqing",
        anim_type = "offensive",
        frequency = Skill.Compulsory,
        events = {fk.PreDamage},
        on_use = function(self, event, target, player, data)
          player.room:loseHp(data.to, data.damage, self.name)
          return true
        end,
    }
    Fk:addSkill(jueqing)
    Fk:loadTranslationTable{
        ["jueqing"] = "绝情",
        [":jueqing"] = "锁定技，你造成的伤害均视为体力流失。",
    }
end
if not Fk.skills["shangshi"] then
    local shangshi = fk.CreateTriggerSkill{
        name = "shangshi",
        anim_type = "drawcard",
        events = {fk.HpChanged, fk.MaxHpChanged, fk.AfterCardsMove},
        can_trigger = function(self, event, target, player, data)
            if player:hasSkill(self) and player:getHandcardNum() < player:getLostHp() then
                if event == fk.AfterCardsMove then
                for _, move in ipairs(data) do
                    if move.from == player.id then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerHand then
                        return true
                        end
                    end
                    end
                end
                else
                return target == player
                end
            end
        end,
        on_use = function(self, event, target, player, data)
            player:drawCards(player:getLostHp() - player:getHandcardNum(), self.name)
        end,
    }
    Fk:addSkill(shangshi)
    Fk:loadTranslationTable{
        ["shangshi"] = "伤逝",
        [":shangshi"] = "当你的手牌数小于你已损失的体力值时，你可以将手牌补至已损失体力值。",
    }
end
if not Fk.skills["benghuai"] then
    local benghuai = fk.CreateTriggerSkill{
        name = "benghuai",
        anim_type = "negative",
        frequency = Skill.Compulsory,
        events = {fk.EventPhaseStart},
        can_trigger = function(self, event, target, player, data)
          return target == player and player:hasSkill(self) and player.phase == Player.Finish and
            table.find(player.room.alive_players, function(p) return p.hp < player.hp end)
        end,
        on_use = function(self, event, target, player, data)
          local room = player.room
          local choice = room:askForChoice(player, {"loseMaxHp", "loseHp"}, self.name)
          if choice == "loseMaxHp" then
            room:changeMaxHp(player, -1)
          else
            room:loseHp(player, 1, self.name)
          end
        end,
    }
    Fk:addSkill(benghuai)
    Fk:loadTranslationTable{
        ["benghuai"] = "崩坏",
        [":benghuai"] = "锁定技，结束阶段，若你不是体力值最小的角色，你选择：1.减1点体力上限；2.失去1点体力。",
    }
end
if not Fk.skills["qice"] then
    local qice = fk.CreateViewAsSkill{
        name = "qice",
        prompt = "#qice-card",
        interaction = function()
          local all_names = U.getAllCardNames("t")
          return U.CardNameBox {
            choices = U.getViewAsCardNames(Self, "qice", all_names),
            all_choices = all_names,
            default_choice = "AskForCardsChosen"
          }
        end,
        card_filter = Util.FalseFunc,
        view_as = function(self, cards)
          if Fk.all_card_types[self.interaction.data] == nil then return end
          local card = Fk:cloneCard(self.interaction.data)
          card:addSubcards(Self:getCardIds(Player.Hand))
          card.skillName = self.name
          return card
        end,
        enabled_at_play = function(self, player)
          return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
        end,
    }
    Fk:addSkill(qice)
    Fk:loadTranslationTable{
        ["qice"] = "奇策",
        [":qice"] = "出牌阶段限一次，你可以将所有的手牌当任意普通锦囊牌使用。",
    }
end
Fk:loadTranslationTable{
    ["ysch4_huangjue"] = "恍觉",
    [":ysch4_huangjue"] = "觉醒技，昂扬技，一个回合开始时，你发现并获得一个觉醒技，然后执行一个仅有出牌阶段的额外回合。激昂：有角色觉醒。激昂：你可以将一个技能当【桃】使用。",
    ["#ysch4_huangjue_trigger"] = "恍觉",
    ["@@ysch4_huangjue"] = "恍觉",
    ["#ysch4_huangjue-choices"] = "恍觉：选择一个觉醒技获得之",
    ["#ysch4_huangjue-prompt"] = "恍觉：将一个技能当【桃】使用",
    ["#ysch4_huangjue-lose"] = "恍觉：请选择一个技能并失去",
    ["ysch4_aohai"] = "遨海",
    [":ysch4_aohai"] = "准备阶段，或你受到伤害时，摸一张牌并加1点体力上限。出牌阶段，你可弃置四张花色各不同的牌并发动“辉逝”。",
    ["#ysch4_aohai_trigger"] = "遨海",
    ["ysch4_limited_huishi"] = "辉逝",
    [":ysch4_limited_huishi"] = "限定技，出牌阶段，你可以选择一名其他角色：若其有未发动过的觉醒技，则你令其发动这些觉醒技时无视原有条件；否则其摸四张牌。最后你减2点体力上限。",
    ["@[:]ysch4_limited_huishi"] = "辉逝",

    ["$ysch4_huangjue1"] = "大梦若期，皆付一枕黄粱。",
    ["$ysch4_huangjue2"] = "日所思之，故夜所梦之。",
    ["$ysch4_aohai1"] = "梦境缥缈，然有迹可占。",
    ["$ysch4_aohai2"] = "万物有兆，唯梦可卜。",
    ["~ysch4__zhouxuan"] = "人生如梦，假时亦真。",
}
local godhuangzhong = General:new(extension, "ysch4__godhuangzhong", "god", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__godhuangzhong"] = "神黄忠",
    ["#ysch4__godhuangzhong"] = "出世真武",
    ["designer:ysch4__godhuangzhong"] = "秀丽&zzcclll朱苦力",
    ["cv:ysch4__godhuangzhong"] = "官方",
    ["illustrator:ysch4__godhuangzhong"] = "佚名",
}
local yunguan = fk.CreateTriggerSkill{
    name = "ysch4_yunguan",
    events = {fk.RoundStart},
    can_trigger = function (self, event, target, player, data)
        local room = player.room
        return player:hasSkill(self.name) and #table.filter(room.alive_players, function (p) return player:inMyAttackRange(p) end) > 0 and
        #table.filter(room.alive_players, function (p) return not player:inMyAttackRange(p) end) > 0
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local bool,dat = room:askForUseActiveSkill(player,"#ysch4_yunguan_active","#ysch4_yunguan_prompt",true)
        if bool then
            self.cost_data = dat
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tos = self.cost_data.targets
        room:setPlayerMark(room:getPlayerById(tos[1]),"@ysch4_yunguan-round",room:getPlayerById(tos[1]):getMark("@ysch4_yunguan-round")-1)
        room:setPlayerMark(room:getPlayerById(tos[2]),"@ysch4_yunguan-round",room:getPlayerById(tos[2]):getMark("@ysch4_yunguan-round")-1)
        room:setPlayerMark(player,"@ysch4_yunguan-round",player:getMark("@ysch4_yunguan-round")+2)
    end,
}
local yunguan_active = fk.CreateActiveSkill{
    name = "#ysch4_yunguan_active",
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_num = 2,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        if #selected > 1 then return false end
        if #selected > 0 then
            local selectOne = Fk:currentRoom():getPlayerById(selected[1])
            local tp = Fk:currentRoom():getPlayerById(to_select)
            if player:inMyAttackRange(selectOne) then
                return not player:inMyAttackRange(tp)
            else
                return player:inMyAttackRange(tp)
            end
        else
            return true
        end
    end,
}
Fk:addSkill(yunguan_active)
local yunguan_attackrange = fk.CreateAttackRangeSkill{
    name = "#ysch4_yunguan_attackrange",
    main_skill = yunling,
    correct_func = function (self, from, to)
        return from:getMark("@ysch4_yunguan-round")
    end,
}
yunguan:addRelatedSkill(yunguan_attackrange)
local yunguan_maxcards = fk.CreateMaxCardsSkill{
    name = "#ysch4_yunguan_maxcards",
    correct_func = function(self, player)
      return player:getMark("@ysch4_yunguan-round")
    end,
}
yunguan:addRelatedSkill(yunguan_maxcards)
local yunguan_visibility = fk.CreateVisibilitySkill{
    name = "#ysch4_yunguan_visibility",
    card_visible = function(self, player, card)
        if player:hasSkill(yunguan.name) then
            local room = Fk:currentRoom()
            local owner = room:getCardOwner(card.id)
            if owner and table.contains(owner.player_cards[Player.Hand], card.id) then
                if owner:getAttackRange() == 0 or owner:isWounded() then
                    return true
                end
            end
        end
    end
}
yunguan:addRelatedSkill(yunguan_visibility)
godhuangzhong:addSkill(yunguan)
local fengxi = fk.CreateActiveSkill{
    name = "ysch4_fengxi",
    card_num = 0,
    target_num = 0,
    card_filter = Util.FalseFunc,
    target_filter = Util.FalseFunc,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) < 1 or
        (player:getMark("ysch4_fengxi-phase") ~= 0 and player:usedSkillTimes(self.name, Player.HistoryPhase) < 2)
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local cards = U.turnOverCardsFromDrawPile(player, -7, self.name)
        local middle = cards[4]
        room:moveCards({
            ids = cards,
            toArea = Card.Processing,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
            proposer = player.id
        })
        room:delay(1500)
        local use = U.askForUseRealCard(room, player, cards, ".|.|.|.|.|equip", self.name, "#ysch4_fengxi-equip", {
            bypass_times = true,
            extraUse = true,
            expand_pile = cards,
        }, false, true)
        if use then
            local dying = false
            if use.card.id == middle and use.card.sub_type == Card.SubtypeWeapon then
                dying = true
            end
            local function indexOf(arr, value)
                for i = 1, #arr, 1 do
                    if arr[i] == value then
                        return i
                    end
                end
                return nil
            end
            local useCards,useCarded = {},{}
            if indexOf(cards,use.card.id) ~= nil and indexOf(cards,use.card.id) ~= 1 then
                table.insert(useCards,cards[indexOf(cards,use.card.id)-1])
            end
            if indexOf(cards,use.card.id) ~= nil and indexOf(cards,use.card.id) ~= 7 then
                table.insert(useCards,cards[indexOf(cards,use.card.id)+1])
            end
            while #useCards > 0 do
                local useCard = U.askForUseRealCard(room, player, cards, ".|.|.|.|.|.|"..table.concat(useCards,","), self.name, "#ysch4_fengxi-use", {
                    bypass_times = true,
                    extraUse = true,
                    expand_pile = cards,
                }, true, true)
                if useCard then
                    table.removeOne(useCards,useCard.card.id)
                    table.insert(useCarded,useCard.card.id)
                    useCard.extra_data = useCard.extra_data or {}
                    useCard.extra_data.ysch4_fengxi = dying
                    room:useCard(useCard)
                else
                    break
                end
            end
            for _, id in ipairs(useCarded) do
                table.removeOne(cards,id)
            end
            table.removeOne(cards,use.card.id)
        else
            local to_throw = room:askForCardsChosen(player, player, 0, 7, {
                card_data = {
                  { "Bottom", cards }
                }
            }, self.name, "#ysch4_fengxi-discard")
            if #to_throw > 0 then
                for _, id in ipairs(to_throw) do
                    table.removeOne(cards,id)
                end
                room:moveCards {ids = to_throw,toArea = Card.DiscardPile,moveReason = fk.ReasonPutIntoDiscardPile,skillName = self.name,proposer = player.id}
            end
            room:setPlayerMark(player,"ysch4_fengxi-phase",1)
        end
        room:moveCards({ids = cards,toArea = Card.DrawPile,moveReason = fk.ReasonJustMove,skillName = self.name,drawPilePosition = -1,})
    end,
}
local fengxi_slashSkill = fk.CreateActiveSkill{
    name = "ysch4_fengxi_slash_skill",
    prompt = function(self, selected_cards)
        local slash = Fk:cloneCard("slash")
        slash.subcards = Card:getIdList(selected_cards)
        local max_num = self:getMaxTargetNum(Self, slash) -- halberd
        if max_num > 1 then
            local num = #table.filter(Fk:currentRoom().alive_players, function (p)
            return p ~= Self and not Self:isProhibited(p, slash)
            end)
            max_num = math.min(num, max_num)
        end
        slash.subcards = {}
        return max_num > 1 and "#slash_skill_multi:::" .. max_num or "#slash_skill"
    end,
    max_phase_use_time = 1,
    target_num = 1,
    can_use = function(self, player, card, extra_data)
        if player:prohibitUse(card) then return end
        return (extra_data and extra_data.bypass_times) or player.phase ~= Player.Play or
            table.find(Fk:currentRoom().alive_players, function(p)
            return self:withinTimesLimit(player, Player.HistoryPhase, card, "slash", p)
            end)
    end,
    mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
        local player = Fk:currentRoom():getPlayerById(to_select)
        local from = Fk:currentRoom():getPlayerById(user)
        return from ~= player and not (distance_limited and not self:withinDistanceLimit(from, true, card, player))
    end,
    target_filter = function(self, to_select, selected, _, card, extra_data)
        if not Util.TargetFilter(self, to_select, selected, _, card, extra_data) then return end
        local count_distances = not (extra_data and extra_data.bypass_distances)
        local target = Fk:currentRoom():getPlayerById(to_select)
        return self:modTargetFilter(to_select, selected, Self.id, card, count_distances) and
        (
            #selected > 0 or
            Self.phase ~= Player.Play or
            (extra_data and extra_data.bypass_times) or
            self:withinTimesLimit(Self, Player.HistoryPhase, card, "slash", target)
        )
    end,
    mute = true,
    on_effect = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.to)
        if not to.dead then
            room:damage({
                from = from,
                to = to,
                card = effect.card,
                damage = to.hp,
                damageType = fk.NormalDamage,
                skillName = self.name
            })
        end
    end
}
Fk:addSkill(fengxi_slashSkill)
local fengxi_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_fengxi_trigger",
    main_skill = fengxi,
    refresh_events = {fk.PreCardEffect},
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill(self.name) and data.from == player.id and data.card.trueName == "slash" and data.extra_data and data.extra_data.ysch4_fengxi == true
    end,
    on_refresh = function (self, event, target, player, data)
        local card = data.card:clone()
        local c = table.simpleClone(data.card)
        for k, v in pairs(c) do
        card[k] = v
        end
        card.skill = fengxi_slashSkill
        data.card = card
    end,
}
fengxi:addRelatedSkill(fengxi_trigger)
godhuangzhong:addSkill(fengxi)
Fk:loadTranslationTable{
    ["ysch4_yunguan"] = "云关",
    [":ysch4_yunguan"] = "轮次开始时，你可以获得攻击范围内外各一名角色本轮的1点攻击范围和手牌上限。攻击范围为0或已受伤角色的手牌对你可见。",
    ["#ysch4_yunguan_active"] = "云关",
    ["#ysch4_yunguan_prompt"] = "是否发动 云关，获得攻击范围内外各一名角色本轮的1点攻击范围和手牌上限",
    ["@ysch4_yunguan-round"] = "云关",
    ["ysch4_fengxi"] = "封息",
    [":ysch4_fengxi"] = "出牌阶段限一次，你可以展示牌堆底七张牌，然后你可使用其中一张装备牌和与之相邻的牌，若因此法使用了处于正中间的武器牌，则你因此法使用的【杀】伤害致命；若你未使用，你可弃置其中任意张牌，然后本阶段此技能限两次。",
    ["#ysch4_fengxi-equip"] = "封息：使用其中一张装备牌",
    ["#ysch4_fengxi-use"] = "封息：你可以使用这些牌",
    ["#ysch4_fengxi-discard"] = "封息：你可以弃置一张任意张牌",
    ["#ysch4_fengxi_trigger"] = "封息",

    ["$ysch4_yunguan1"] = "流不尽的英雄血，斩不尽的逆贼头！",
    ["$ysch4_yunguan2"] = "长刀渴血，当饲英雄胆！",
    ["$ysch4_fengxi1"] = "横眉蔑风雨，引弓狩天狼。",
    ["$ysch4_fengxi2"] = "一箭出，万军毙！",
}
local yijue = General:new(extension, "ysch4__iso", "zishu", 4, 4, General.Male)--
yijue.shield = 1
Fk:loadTranslationTable{
    ["ysch4__iso"] = "壹决",
    ["#ysch4__iso"] = "单打王",
    ["designer:ysch4__iso"] = "辛涟月",
    ["cv:ysch4__iso"] = "佚名",
    ["illustrator:ysch4__iso"] = "无畏契约",
}
local zhanshuxinliu = fk.CreateTriggerSkill{
    name = "ysch4_zhanshuxinliu",
    events = {fk.DamageCaused, fk.DamageInflicted},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self.name) then
            local cards = player.player_cards[Player.Hand]
            if #cards > 0 then
                for _, id in ipairs(cards) do
                    if Fk:getCardById(id).color == Card.NoColor or Fk:getCardById(id).color ~= Fk:getCardById(cards[1]).color then
                        return false
                    end
                end
                return true
            end
        end
    end,
    mute = true,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local prompt = "#ysch4_zhanshuxinliu-prompt1:"..data.to.id
        if event == fk.DamageInflicted then
            prompt = "#ysch4_zhanshuxinliu-prompt2:"..data.from.id
        end
        if room:askForSkillInvoke(player,self.name,nil,prompt) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = table.filter(player:getCardIds("h"), function (id)
            return not table.contains(GetShownCards(player), id)
        end)
        local card = nil
        if #cards > 0 then
            player:broadcastSkillInvoke(self.name)
            room:notifySkillInvoked(player,self.name,"defensive")
            card = room:askForCard(player, 2, 2, false, self.name, true, tostring(Exppattern{ id = cards }),
            "#ysch4_zhanshuxinliu-show")
        end
        if card ~= nil and #card > 0 then
            for _, id in ipairs(card) do
                room:setCardMark(Fk:getCardById(id), '@@ShownCards-inhand', 1)
            end
            return true
        else
            player:broadcastSkillInvoke(self.name)
            room:notifySkillInvoked(player,self.name,"drawcard")
            room:recastCard(player:getCardIds("h"), player, self.name)
            local current = data.to
            if event == fk.DamageInflicted then
                current = data.from
            end
            if current and current.id ~= player.id then
                room.logic:getCurrentEvent().parent:addCleaner(function ()
                    if not current.dead then
                        local use = room:askForUseCard(player, self.name, "slash",
                            "#ysch4_zhanshuxinliu-use:"..current.id, true, {exclusive_targets = {current.id} })
                        if use then
                            room:useCard(use)
                        end
                    end
                end)
            end
        end
    end,
}
yijue:addSkill(zhanshuxinliu)
local juedoutongdie = fk.CreateTriggerSkill{
    name = "ysch4_juedoutongdie",
    mute = true,
    events = {fk.EventPhaseStart},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Start and player:getMark("@@rfenghou_readying:::"..self.name) == 0
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.map(table.filter(room.alive_players, function(p) return p ~= player end), Util.IdMapper)
        local to = room:askForChoosePlayers(player, targets, 1, 1, "#ysch4_juedoutongdie-prompt", self.name, true)
        if #to > 0 then
            self.cost_data = to[1]
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data)
        room:notifySkillInvoked(player,self.name,"offensive")
        player:broadcastSkillInvoke(self.name,table.random({1,2}))

        if player:getHandcardNum() - 4 > 0 then
            room:askForDiscard(player, player:getHandcardNum() - 4, player:getHandcardNum() - 4, true, self.name, false)
        else
            player:drawCards(4 - player:getHandcardNum(), self.name)
        end
        if to:getHandcardNum() - 4 > 0 then
            room:askForDiscard(to, to:getHandcardNum() - 4, to:getHandcardNum() - 4, true, self.name, false)
        else
            to:drawCards(4 - to:getHandcardNum(), self.name)
        end
        room:changeHp(player, 4 - player.hp, nil, self.name)
        room:changeHp(to, 4 - to.hp, nil, self.name)

        local winner = nil
        while player:getHandcardNum() > 0 and to:getHandcardNum() > 0 do
            local pindian = player:pindian({to}, self.name)
            if pindian and pindian.results[to.id] then
            winner = pindian.results[to.id].winner
                if winner then
                    local slash = Fk:cloneCard("slash")
                    slash.skillName = self.name
                    if winner == player then
                        room:useCard{
                            from = player.id,
                            card = slash,
                            tos = { { to.id } },
                            extraUse = true,
                        }
                    else
                        room:useCard{
                            from = to.id,
                            card = slash,
                            tos = { { player.id } },
                            extraUse = true,
                        }
                    end
                end
            end
        end
        if winner then
            if winner == player then
                player:broadcastSkillInvoke(self.name,3)
                room:killPlayer({who = to.id, damage = {to = target, damage = 1, from = player}})
            else
                room:killPlayer({who = player.id, damage = {to = player, damage = 1, from = to}})
            end
        end
    end,
}
juedoutongdie.RfenghouReadySkill = true
yijue:addSkill(juedoutongdie)
Fk:loadTranslationTable{
    ["ysch4_zhanshuxinliu"] = "战术心流",
    [":ysch4_zhanshuxinliu"] = "当你受到或造成伤害时，若你有手牌且颜色相同，你可以明置两张手牌防止之，或重铸手牌并可以于结算后对其使用一张【杀】。",
    ["#ysch4_zhanshuxinliu-show"] = "战术心流：明置两张手牌防止此伤害，或点“取消”重铸手牌",
    ["#ysch4_zhanshuxinliu-use"] = "战术心流：你可以对 %src 使用一张【杀】",
    ["#ysch4_zhanshuxinliu-prompt1"] = "你即将对%src造成伤害，是否发动 战术心流",
    ["#ysch4_zhanshuxinliu-prompt2"] = "%src即将对你造成伤害，是否发动 战术心流",
    ["ysch4_juedoutongdie"] = "决斗通牒",
    [":ysch4_juedoutongdie"] = "蓄势技，准备阶段，你可以与一名其他角色共同调整手牌数与体力值为4，然后与其连续拼点直至一方没有手牌。每次赢的角色视为对对方使用一张【杀】；最后一次拼点赢的角色杀死对方。",
    ["#ysch4_juedoutongdie-prompt"] = "是否发动 决斗通牒，与一名其他角色进行单挑！",
    ["@@rfenghou_readying:::ysch4_juedoutongdie"] = "决斗通牒 蓄势中",

    ["$ysch4_zhanshuxinliu1"] = "全力集中！",
    ["$ysch4_zhanshuxinliu2"] = "告诉我，目标在哪？",
    ["$ysch4_juedoutongdie1"] = "拔抢吧，就你和我！",
    ["$ysch4_juedoutongdie2"] = "这是我的决斗！",
    ["$ysch4_juedoutongdie3"] = "结束了，打得不错。",
}
local Jinx = General:new(extension, "ysch4__Jinx", "west", 3, 3, General.Female)--
Jinx.shield = 1
Fk:loadTranslationTable{
    ["ysch4__Jinx"] = "金克丝",
    ["#ysch4__Jinx"] = "暴走萝莉",
    ["designer:ysch4__Jinx"] = "Sachiko",
    ["cv:ysch4__Jinx"] = "佚名",
    ["illustrator:ysch4__Jinx"] = "英雄联盟",
}
local zuiekuaigan = fk.CreateTriggerSkill{
    name = "ysch4_zuiekuaigan",
    dynamic_desc = function (self, player, lang)
        if not player:hasSkill("ysch4_sishenfeidan") then
            return "锁定技，当你造成或受到伤害后，你摸四张牌并弃置X张牌，然后你使用【杀】的次数＋1。（X为你本回合发动技能的次数）"
        else
            return "锁定技，当你造成或受到伤害后，你摸四张牌并弃置X张牌，然后你使用【杀】的次数＋1。"
        end
    end,
    frequency = Skill.Compulsory,
    anim_type = "drawcard",
    events = {fk.Damage, fk.Damaged},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self)
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:drawCards(4,self.name)
        local x = 0
        for k, v in pairs(player.skillUsedHistory) do
            if player:hasSkill(k) and Fk.skills[k]:isPlayerSkill(player) and not k:startsWith("#") and player.skillUsedHistory[k][Player.HistoryTurn] then
                x = x + player.skillUsedHistory[k][Player.HistoryTurn]
            end
        end
        room:askForDiscard(player, x, x, true, self.name, false, nil, "#ysch4_zuiekuaigan-discard:::"..x)
        room:addPlayerMark(player,"@ysch4_zuiekuaigan")
    end,
  
    on_lose = function (self, player)
        player.room:setPlayerMark(player, "@steam__wanghe", 0)
    end,
}
local zuiekuaigan_targetmod = fk.CreateTargetModSkill{
    name = "#ysch4_zuiekuaigan_targetmod",
    frequency = Skill.Compulsory,
    residue_func = function(self, player, skill)
        if player:hasSkill(self) and skill and skill.trueName == "slash_skill" and player.phase == Player.Play then
            return player:getMark("@ysch4_zuiekuaigan")
        end
    end,
}
zuiekuaigan:addRelatedSkill(zuiekuaigan_targetmod)
Jinx:addSkill(zuiekuaigan)
local qiangpaojiaoxiang = fk.CreateTriggerSkill{
    name = "ysch4_qiangpaojiaoxiang",
    switch_skill_name = "ysch4_qiangpaojiaoxiang",
    dynamic_desc = function (self, player, lang)
        if not player:hasSkill("ysch4_sishenfeidan") then
            return "转换技，你使用【杀】后，可以重铸X张牌面信息有“杀”的牌，然后你使用的下一张【杀】①额外结算一次②伤害基数翻倍。（X为你本回合发动技能的次数）"
        else
            return "转换技，你使用【杀】后，可以重铸X张牌面信息有“杀”的牌，然后你使用的下一张【杀】①额外结算一次②伤害基数翻倍。"
        end
    end,
    anim_type = "switch",
    events = {fk.CardUseFinished},
    can_trigger = function (self, event, target, player, data)
        if target == player and player:hasSkill(self.name) then
            return data.card.trueName == "slash"
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local x = 1
        for k, v in pairs(player.skillUsedHistory) do
            if player:hasSkill(k) and Fk.skills[k]:isPlayerSkill(player) and k:startsWith("#") and player.skillUsedHistory[k][Player.HistoryTurn] then
                x = x + player.skillUsedHistory[k][Player.HistoryTurn]
            end
        end
        local cards = table.filter(player:getCardIds("he"),function (id)
            local card = Fk:getCardById(id)
            local name = card.name
            return string.find(Fk:translate(name, "zh_CN"), "杀") ~= nil or string.find(Fk:translate(":" .. name, "zh_CN"), "【杀】") ~= nil
        end)
        local choose = room:askForCard(player,x,x,true,self.name,true,tostring(Exppattern{id = cards}),"#ysch4_qiangpaojiaoxiang-prompt:::"..x)
        if #choose > 0 then
            self.cost_data = choose
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:recastCard(self.cost_data,player,self.name)
        if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
            room:setPlayerMark(player,"@@ysch4_qiangpaojiaoxiang1",1)
        else
            room:setPlayerMark(player,"@@ysch4_qiangpaojiaoxiang2",1)
        end
    end,

    refresh_events = {fk.CardUsing},
    can_refresh = function (self, event, target, player, data)
        if target == player and data.card.trueName == "slash" then
            return player:getMark("@@ysch4_qiangpaojiaoxiang1") > 0 or player:getMark("@@ysch4_qiangpaojiaoxiang2") > 0
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if player:getMark("@@ysch4_qiangpaojiaoxiang1") > 0 then
            room:setPlayerMark(player, "@@ysch4_qiangpaojiaoxiang1", 0)
            data.additionalEffect = (data.additionalEffect or 0) + 1
        end
        if player:getMark("@@ysch4_qiangpaojiaoxiang2") > 0 then
            room:setPlayerMark(player, "@@ysch4_qiangpaojiaoxiang2", 0)
            data.additionalDamage = (data.additionalDamage or 1) + (data.additionalDamage or 1)
        end
    end,
}
Jinx:addSkill(qiangpaojiaoxiang)
local sishenfeidan = fk.CreateActiveSkill{
    name = "ysch4_sishenfeidan",
    frequency = Skill.Limited,
    card_filter = Util.FalseFunc,
    anim_type = "big",
    card_num = 0,
    target_num = 1,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        return to_select ~= player.id
    end,
    prompt = function (self, selected_cards, selected_targets)
        local x = 1
        for k, v in pairs(Self.skillUsedHistory) do
            if Self:hasSkill(k) and Fk.skills[k]:isPlayerSkill(Self) and not k:startsWith("#") and Self.skillUsedHistory[k][Player.HistoryTurn] then
                x = x + Self.skillUsedHistory[k][Player.HistoryTurn]
            end
        end
        return "#ysch4_sishenfeidan-prompt:::"..x
    end,
    can_use = function (self, player, card, extra_data)
        return player:usedSkillTimes(self.name,Player.HistoryGame) == 0 and #table.filter(player:getTableMark("ysch4_sishenfeidan"),function (id)
            local card = Fk:getCardById(id)
            return card.trueName == "slash"
        end) > #player:getTableMark("ysch4_sishenfeidan")/2
    end,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        room:setPlayerMark(player,"@ysch4_sishenfeidan-turn",0)
        local tos = effect.tos
        for _, pid in ipairs(tos) do
            local to = room:getPlayerById(pid)
            if not to.dead then
                to:setChainState(true)
            end
        end
        local x = 0
        for k, v in pairs(player.skillUsedHistory) do
            if player:hasSkill(k) and Fk.skills[k]:isPlayerSkill(player) and not k:startsWith("#") and player.skillUsedHistory[k][Player.HistoryTurn] then
                x = x + player.skillUsedHistory[k][Player.HistoryTurn]
            end
        end
        for _, pid in ipairs(tos) do
            local to = room:getPlayerById(pid)
            if not to.dead then
                room:damage {
                    from = player, to = to,
                    damage = x, damageType = fk.FireDamage, skillName = self.name
                }
            end
        end
    end,
}
local sishenfeidan_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_sishenfeidan_trigger",
    main_skill = sishenfeidan,
    refresh_events = {fk.SkillEffect,fk.StartPlayCard},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(sishenfeidan.name) and target == player and player:usedSkillTimes(sishenfeidan.name,Player.HistoryGame) == 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local x = 0
        for k, v in pairs(player.skillUsedHistory) do
            if player:hasSkill(k) and Fk.skills[k]:isPlayerSkill(player) and not k:startsWith("#") and player.skillUsedHistory[k][Player.HistoryTurn] then
                x = x + player.skillUsedHistory[k][Player.HistoryTurn]
            end
        end
        room:setPlayerMark(player,"@ysch4_sishenfeidan-turn",x)

        local cards = {}
        room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
            for _, move in ipairs(e.data) do
                if move.toArea == Card.DiscardPile then
                    for _, info in ipairs(move.moveInfo) do
                        if table.contains(room.discard_pile, info.cardId) then
                            table.insertIfNeed(cards, info.cardId)
                        end
                    end
                end
            end
        end, Player.HistoryTurn)
        room:setPlayerMark(player, "ysch4_sishenfeidan", cards)
    end,
}
sishenfeidan:addRelatedSkill(sishenfeidan_trigger)
sishenfeidan.CenterArea = true
Jinx:addSkill(sishenfeidan)
Fk:loadTranslationTable{
    ["ysch4_zuiekuaigan"] = "罪恶快感",
    [":ysch4_zuiekuaigan"] = "锁定技，当你造成或受到伤害后，你摸四张牌并弃置X张牌，然后你使用【杀】的次数＋1。",
    ["#ysch4_zuiekuaigan-discard"] = "罪恶快感：请弃置 %arg 张牌",
    ["@ysch4_zuiekuaigan"] = "罪恶快感",
    ["ysch4_qiangpaojiaoxiang"] = "枪炮交响",
    [":ysch4_qiangpaojiaoxiang"] = "转换技，你使用【杀】后，可以重铸X张牌面信息有“杀”的牌，然后你使用的下一张【杀】①额外结算一次②伤害基数翻倍。",
    ["#ysch4_qiangpaojiaoxiang-prompt"] = "枪炮交响：你可以重铸 %arg 张牌面信息含“杀”牌",
    ["@@ysch4_qiangpaojiaoxiang1"] = "杀 额外结算",
    ["@@ysch4_qiangpaojiaoxiang2"] = "杀 伤害翻倍",
    ["ysch4_sishenfeidan"] = "死神飞弹",
    [":ysch4_sishenfeidan"] = "限定技，出牌阶段，若中央区【杀】的数量更多，则你可以对一名其他角色造成X点火焰伤害（X为你本回合发动技能的次数），且其先横置。",
    ["@ysch4_sishenfeidan-turn"] = "死神飞弹",
    ["#ysch4_sishenfeidan-prompt"] = "死神飞弹：你可以对一名其他角色造成 %arg 点火焰伤害",

    ["$ysch4_zuiekuaigan1"] = "规则？就是用来打破的！",
    ["$ysch4_zuiekuaigan2"] = "你觉得我很疯狂？你该看看我的姐妹！",
    ["$ysch4_zuiekuaigan3"] = "哈哈，有谁需要理由？",
    ["$ysch4_zuiekuaigan4"] = "我是个疯子，有医生开的证明。",
    ["$ysch4_qiangpaojiaoxiang1"] = "不管怎样，让我们开始开枪吧！",
    ["$ysch4_qiangpaojiaoxiang2"] = "没有害怕的必要，也没有活着的必要！",
    ["$ysch4_qiangpaojiaoxiang3"] = "笑一下，我们在玩射击游戏呢！",
    ["$ysch4_qiangpaojiaoxiang4"] = "金克丝的含义，就是金克丝，笨！",
    ["$ysch4_sishenfeidan1"] = "大家都恐慌起来吧！",
    ["$ysch4_sishenfeidan2"] = "我意外地做到了！",
    ["$ysch4_sishenfeidan3"] = "我想都没想过，能有朝一日引爆全场！",
    ["$ysch4_sishenfeidan4"] = "3、41、9，然后——起飞咯！",
    ["~ysch4__Jinx"] = "他们，干掉我了——呃~",
}
local quniang = General:new(extension, "ysch4__quniang", "qun", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__quniang"] = "曲娘",
    ["#ysch4__quniang"] = "石子的顽然",
    ["designer:ysch4__quniang"] = "胖即是胖",
    ["cv:ysch4__quniang"] = "佚名",
    ["illustrator:ysch4__quniang"] = "重返未来1999",
}
local cunxiang = fk.CreateViewAsSkill{
    name = "ysch4_cunxiang",
    switch_skill_name = "ysch4_cunxiang",
    anim_type = "support",
    pattern = "analeptic",
    card_filter = Util.FalseFunc,
    prompt = function (self, selected_cards, selected)
        if Self:getSwitchSkillState(self.name, true) == fk.SwitchYang then
            return "存想：你可以摸两张牌视为使用一张【酒】"
        else
            return "存想：你可以翻至背面视为使用一张【酒】"
        end
    end,
    before_use = function(self, player)
        if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
            player:turnOver()
        else
            player:drawCards(2,self.name)
        end
    end,
    view_as = function(self, cards)
        local c = Fk:cloneCard("analeptic")
        c.skillName = self.name
        return c
    end,
    enabled_at_play = function (self, player)
        return player.faceup or player:getSwitchSkillState(self.name, true) == fk.SwitchYang
    end,
    enabled_at_response = function (self, player,response)
        return not response and (player.faceup or player:getSwitchSkillState(self.name, true) == fk.SwitchYang)
    end,
}
quniang:addSkill(cunxiang)
local jinxing = fk.CreateTriggerSkill{
    name = "ysch4_jinxing",
    events = {fk.RoundEnd},
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        return #player.room.logic:getEventsOfScope(GameEvent.Turn, 1, function (e)
            return e.data[1] == player
        end, Player.HistoryRound) == 0
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,"@@ysch4_jinxing-turn",1)
        player:gainAnExtraTurn(true, self.name)
    end,
}
local jinxing_targetmod = fk.CreateTargetModSkill{
    name = "#ysch4_jinxing_targetmod",
    bypass_times = function(self, player, skill, scope, card)
        return player:getMark("@@ysch4_jinxing-turn") ~= 0 and card
    end,
}
jinxing:addRelatedSkill(jinxing_targetmod)
quniang:addSkill(jinxing)
Fk:loadTranslationTable{
    ["ysch4_cunxiang"] = "存想",
    [":ysch4_cunxiang"] = "转换技，当你需要使用【酒】时，你可以①将武将牌翻至背面②摸两张牌，然后你视为使用之。",
    ["ysch4_jinxing"] = "尽兴",
    [":ysch4_jinxing"] = "每轮结束时，若你本轮未执行过回合，你执行一个额外的回合；你于此回合内使用牌无次数限制。",
    ["@@ysch4_jinxing-turn"] = "尽兴 无次数限制",
}
local simayiw = General:new(extension, "ysch4__simayiw", "jin", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__simayiw"] = "司马乂",
    ["#ysch4__simayiw"] = "懿遗熠夷",
    ["designer:ysch4__simayiw"] = "屑",
    ["cv:ysch4__simayiw"] = "佚名",
    ["illustrator:ysch4__simayiw"] = "佚名",
}
local zhuoman = fk.CreateTriggerSkill{
    name = "ysch4_zhuoman",
    anim_type = "control",
    events = {fk.AfterCardTargetDeclared},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and data.card.is_damage_card and player:distanceTo(target) <= 1
    end,
    dynamic_desc = function (self, player, lang)
        if Fk:currentRoom():isGameMode("1v2_mode") or Fk:currentRoom():isGameMode("hell_combat_mode") then
            return "你距离1内的角色使用伤害牌指定目标后，你可以为之多指定一个目标（无视合法性），令额外目标先结算此牌，且其因此受伤时，其令此牌无法抵消或无效，然后你摸两张牌。"
        end
        return "你距离1内的角色使用伤害牌指定目标后，你可以为之多指定一个目标（无视合法性），令额外目标先结算此牌，且其因此受伤时，其令此牌无法抵消或无效，然后你重铸一张牌。"
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = {}
        for _, cp in ipairs(room.alive_players) do
            --[[if not table.contains(table.map(data.tos,function (info)
                return info[1]
            end),cp.id) then]]--
            table.insert(targets,cp.id)
            --end
        end
        local to = player.room:askForChoosePlayers(player, targets, 1, 1,
            "#ysch4_zhuoman-choose:::"..data.card:toLogString(), self.name, true)
        if #to > 0 then
            self.cost_data = to
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        for index, value in ipairs(self.cost_data) do
            --if not table.contains(AimGroup:getAllTargets(data.tos), value) then
            TargetGroup:pushTargets(data.tos, value)
            --end
        end
        room:sendLog{
            type = "#ysch4_zhuoman-log1",
            from = player.id,
            arg = self.name,
            arg2 = data.card:toLogString(),
            to = self.cost_data,
        }
        data.extra_data = data.extra_data or {}
        data.extra_data.ysch4_zhuoman = {}
        table.insert(data.extra_data.ysch4_zhuoman,{player.id, self.cost_data})
    end,

    refresh_events = {fk.BeforeCardUseEffect,fk.DamageInflicted},
    can_refresh = function (self, event, target, player, data)
        if event == fk.BeforeCardUseEffect then
            return data.extra_data and data.extra_data.ysch4_zhuoman
        else
            if data.card == nil then return false end
            local room = player.room
            local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
            if not card_event then return false end
            local use = card_event.data[1]
            if use.extra_data and use.extra_data.ysch4_zhuoman then
                for _, value in ipairs(use.extra_data.ysch4_zhuoman) do
                    if value[1] == player.id and table.contains(value[2],target.id) then
                        return true
                    end
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.BeforeCardUseEffect then
            local extraTos = {}
            for _, value in ipairs(data.extra_data.ysch4_zhuoman) do
                for _, info in ipairs(value[2]) do
                    if room:isGameMode("1v2_mode") or room:isGameMode("hell_combat_mode") then
                        table.insert(extraTos,info)
                    else
                        table.insertIfNeed(extraTos,info)
                    end
                end
            end
            local new_tos = {}
            for _, info in ipairs(data.tos) do
                if table.contains(extraTos,info[1]) then
                    table.insert(new_tos, info)
                end
            end
            for _, info in ipairs(data.tos) do
                if not table.contains(extraTos,info[1]) then
                    table.insert(new_tos, info)
                end
            end
            data.tos = new_tos
        else
            local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
            if card_event and card_event.data[1] then
                local use = card_event.data[1]
                local choice = room:askForChoice(target,{"#ysch4_zhuoman1","#ysch4_zhuoman2"},self.name,"#ysch4_zhuoman-choice:::"..data.card:toLogString())
                local list = use.nullifiedTargets or {}
                if choice == "#ysch4_zhuoman1" then
                    list = use.disresponsiveList or {}
                end
                for _, cp in ipairs(room.alive_players) do
                    table.insertIfNeed(list, cp.id)
                end
                if choice == "#ysch4_zhuoman1" then
                    use.disresponsiveList = list
                else
                    use.nullifiedTargets = list
                end
                room:sendLog{
                    type = "#ysch4_zhuoman-log2",
                    from = target.id,
                    arg = data.card:toLogString(),
                    arg2 = choice,
                    toast = true,
                }
                if room:isGameMode("1v2_mode") or room:isGameMode("hell_combat_mode") then
                    player:drawCards(2,self.name)
                else
                    if not player:isNude() then
                        local recast = room:askForCard(player, 1, 1, true, self.name, false,".", "#ysch4_zhuoman-recast")
                        room:recastCard(recast, player, self.name)
                    end
                end
            end
        end
    end,
}
simayiw:addSkill(zhuoman)
Fk:loadTranslationTable{
    ["ysch4_zhuoman"] = "斫幔",
    [":ysch4_zhuoman"] = "你距离1内的角色使用伤害牌指定目标后，你可以为之多指定一个目标（无视合法性），令额外目标先结算此牌，且其因此受伤时，其令此牌无法抵消或无效，然后你重铸一张牌。",
    ["#ysch4_zhuoman-choose"] = "斫幔：你可以为%arg多指定一个目标",
    ["#ysch4_zhuoman1"] = "无法响应",
    ["#ysch4_zhuoman2"] = "无效",
    ["#ysch4_zhuoman-choice"] = "斫幔：你须令此牌（%arg）",
    ["#ysch4_zhuoman-recast"] = "斫幔：重铸一张牌",
    ["#ysch4_zhuoman-log1"] = "%from 发动了〖%arg〗，为 %arg2 额外指定了目标 %to",
    ["#ysch4_zhuoman-log2"] = "%from 令 %arg %arg2",
}
local fanjin = General:new(extension, "ysch4__fanjin", "song", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["song"] = "宋",
    ["ysch4__fanjin"] = "范进",
    ["#ysch4__fanjin"] = "",
    ["designer:ysch4__fanjin"] = "长妤眠",
    ["cv:ysch4__fanjin"] = "佚名",
    ["illustrator:ysch4__fanjin"] = "佚名",
}
fanjin.total_hidden = true
local zhongju = fk.CreateTriggerSkill{
    name = "ysch4_zhongju",
    dynamic_desc = function (self, player, lang)
        if Self:getMark(self.name) ~= 0 then
            return "你的手牌数从众数变至不为众数，或从不为众数变为众数时，你摸一张牌。"
        else
            return "你的手牌数从众数变至更多时，你摸一张牌并修改“<a href='ysch4_zhongju_plus'>中举</a>”。"
        end
    end,
    events = {fk.AfterCardsMove},
    anim_type = "drawcard",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            return data.extra_data and data.extra_data.ysch4_zhongju == player.id
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,self.name,1)
        player:drawCards(1,self.name)
    end,

    refresh_events = {fk.GameStart,fk.AfterCardsMove},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(self.name)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local modenums, map, max = {}, {}, 0
        for _, p in ipairs(room.alive_players) do
            local num = p:getHandcardNum()
            map[num] = (map[num] or 0) + 1
            max = math.max(max, map[num])
        end
        for i, num in pairs(map) do
            if num == max then
                table.insert(modenums, i)
            end
        end
        if table.contains(modenums, player:getHandcardNum()) or player:getMark(self.name) == 0 then
            if event == fk.AfterCardsMove then
                if player:getMark(self.name) ~= 0 and player:getMark("@ysch4_zhongju") == 0 then
                    for _, move in ipairs(data) do
                        if (move.from == player.id and table.find(move.moveInfo, function (info)
                            return info.fromArea == Card.PlayerHand
                          end)) or (move.to == player.id and move.toArea == Card.PlayerHand) then
                            data.extra_data = data.extra_data or {}
                            data.extra_data.ysch4_zhongju = player.id
                        end
                    end
                elseif player:getMark(self.name) == 0 and player:getMark("@ysch4_zhongju") ~= 0 then
                    for _, move in ipairs(data) do
                        if move.to == player.id and move.toArea == Card.PlayerHand then
                            data.extra_data = data.extra_data or {}
                            data.extra_data.ysch4_zhongju = player.id
                        end
                    end
                end
            end
            room:setPlayerMark(player,"@ysch4_zhongju",table.concat(modenums," "))
        else
            if event == fk.AfterCardsMove and player:getMark("@ysch4_zhongju") ~= 0 and (table.filter(modenums,function(num) return player:getHandcardNum() > num end) or player:getMark(self.name) ~= 0) then
                for _, move in ipairs(data) do
                    if (player:getMark(self.name) ~= 0 and move.from == player.id and table.find(move.moveInfo, function (info)
                        return info.fromArea == Card.PlayerHand
                    end)) or (move.to == player.id and move.toArea == Card.PlayerHand) then
                        data.extra_data = data.extra_data or {}
                        data.extra_data.ysch4_zhongju = player.id
                    end
                end
            end
            room:setPlayerMark(player,"@ysch4_zhongju",0)
        end
    end,
}
fanjin:addSkill(zhongju)
local yiwu = fk.CreateActiveSkill{
    name = "ysch4_yiwu",
    anim_type = "drawcard",
    can_use = function(self, player)
      return not player:isNude()
    end,
    card_num = 1,
    card_filter = function(self, to_select, selected)
        return #selected < 1 and Fk:getCardById(to_select).type == Card.TypeTrick
    end,
    target_num = 0,
    on_use = function(self, room, effect)
        room:recastCard(effect.cards, room:getPlayerById(effect.from), self.name)
    end,
}
fanjin:addSkill(yiwu)
Fk:loadTranslationTable{
    ["ysch4_zhongju"] = "中举",
    [":ysch4_zhongju"] = "你的手牌数从众数变至更多时，你摸一张牌并修改“<a href='ysch4_zhongju_plus'>中举</a>”。",
    ["ysch4_zhongju_plus"] = "<b>中举·改</b>：你的手牌数从众数变至不为众数，或从不为众数变为众数时，你摸一张牌。",
    ["@ysch4_zhongju"] = "众数",
    ["ysch4_yiwu"] = "噫唔",
    [":ysch4_yiwu"] = "出牌阶段，你可以重铸一张锦囊牌。",
}
local liuxiu = General:new(extension, "ysch4__liuxiu", "han", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__liuxiu"] = "刘秀",
    ["#ysch4__liuxiu"] = "炎精更辉",
    ["designer:ysch4__liuxiu"] = "独孤妙妙",
    ["cv:ysch4__liuxiu"] = "佚名",
    ["illustrator:ysch4__liuxiu"] = "佚名",
}
local chengxing = fk.CreateTriggerSkill{
    name = "ysch4_chengxing",
    mute = true,
    events = {fk.DrawInitialCards,fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            if event ~= fk.TurnEnd then
                return true
            else
                return #table.filter(player.room:getAlivePlayers(),function (cp)
                    return cp:getMark("__hidden_general") ~= 0 or cp:getMark("__hidden_deputy") ~= 0
                end) == 0
            end
        end
    end,
    anim_type = "big",
    frequency = Skill.Compulsory,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event ~= fk.TurnEnd then
            player:broadcastSkillInvoke(self.name,table.random({1,2}))
            --room:notifySkillInvoked(player,self.name,"big")
            for _, cp in ipairs(table.random(room:getAlivePlayers(),999)) do
                if cp.general ~= "hiddenone" and ((cp.deputyGeneral ~= "" and cp.deputyGeneral ~= "hiddenone") or not cp.deputyGeneral ~= "" ) then
                    DIYEnterHidden(cp)
                end
            end
            for _, cp in ipairs(table.random(room:getAlivePlayers(),999)) do
                room:handleAddLoseSkills(cp,"ysch4_tianshouu")
            end
        else
            player:broadcastSkillInvoke(self.name,3)
            room:notifySkillInvoked(player,self.name,"big")
            local winner = room:getPlayerById(player:getMark(self.name))
            local role = winner.role
            if role == "lord" or role == "loyalist" then
                role = "lord+loyalist"
            end
            room:gameOver(role)
        end
    end,

    refresh_events = {"fk.GeneralAppeared"},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(self.name)
        --[[return target == player and #table.filter(player.room:getAlivePlayers(),function (cp)
            return cp:hasSkill(self.name)
        end) > 0]]--
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        room:handleAddLoseSkills(target,"-ysch4_tianshouu")
        if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
        string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil then
            if room:askForSkillInvoke(target,self.name,nil,"#ysch4_chengxing-rename") then
                target.general = "ysch4__liuxiu"
                room:broadcastProperty(target, "general")
            end
        end

        if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") ~= nil or 
        string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") ~= nil then
            room:setPlayerMark(player,self.name,target.id)
            room:setPlayerMark(player,"@ysch4_chengxing","seat#"..tostring(target.seat))
        end
    end,
}
liuxiu:addSkill(chengxing)
local tianshou = fk.CreateTriggerSkill{
    name = "ysch4_tianshou",
    frequency = Skill.Limited,
    events = {"fk.GeneralAppeared"},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0 then
            if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
            string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil then
                return #table.filter(player.room:getAlivePlayers(),function (cp)
                    return cp:getMark("__hidden_general") ~= 0 or cp:getMark("__hidden_deputy") ~= 0
                end) > 0
            else
                return #table.filter(player.room:getOtherPlayers(target),function (cp)
                    return string.find(Fk:translate(cp.general, "zh_CN"), "刘秀") ~= nil or
                    string.find(Fk:translate(cp.deputyGeneral, "zh_CN"), "刘秀") ~= nil
                end) > 0
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = {}
        local str = "是否发动 天授，令另一名“刘秀”摸两张牌并隐匿"
        if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
        string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil then
            targets = table.map(table.filter(room:getAlivePlayers(),function (cp)
                return cp:getMark("__hidden_general") ~= 0 or cp:getMark("__hidden_deputy") ~= 0
            end),function (cp)
                return cp.id
            end)
            str = "是否发动 天授，令一名隐匿角色弃两张牌并登场"
        else
            targets = table.map(table.filter(room:getOtherPlayers(target),function (cp)
                return string.find(Fk:translate(cp.general, "zh_CN"), "刘秀") ~= nil or
                string.find(Fk:translate(cp.deputyGeneral, "zh_CN"), "刘秀") ~= nil
            end),function (cp)
                return cp.id
            end)
        end
        local tos = room:askForChoosePlayers(player,targets,1,1,str,self.name)
        if #tos > 0 then
            self.cost_data = tos[1]
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data)
        if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
        string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil then
            room:askForDiscard(to, 2, 2, true, self.name, false)

            room:handleAddLoseSkills(to, "-hidden_skill&", nil, false, true)
            if Fk.generals[to:getMark("__hidden_general")] then
            to.general = to:getMark("__hidden_general")
            end
            if Fk.generals[to:getMark("__hidden_detouty")] then
            to.deputyGeneral = to:getMark("__hidden_deputy")
            end
            room:setPlayerMark(to, "__hidden_general", 0)
            room:setPlayerMark(to, "__hidden_deputy", 0)
            local general = Fk.generals[to.general]
            local deputy = Fk.generals[to.deputyGeneral]
            to.gender = general.gender
            to.kingdom = general.kingdom
            room:broadcastProperty(to, "gender")
            room:broadcastProperty(to, "general")
            room:broadcastProperty(to, "deputyGeneral")
            room:askForChooseKingdom({to})
            room:broadcastProperty(to, "kingdom")
            
            to.maxHp = to:getGeneralMaxHp()
            to.hp = deputy and math.floor((deputy.hp + general.hp) / 2) or general.hp
            to.shield = math.min(general.shield + (deputy and deputy.shield or 0), 5)
            local changer = Fk.game_modes[room.settings.gameMode]:getAdjustedProperty(to)
            if changer then
            for key, value in pairs(changer) do
                to[key] = value
            end
            end
            room:broadcastProperty(to, "maxHp")
            room:broadcastProperty(to, "hp")
            room:broadcastProperty(to, "shield")

            local lordBuff = to.role == "lord" and to.role_shown == true and #room.players > 4
            local skills = general:getSkillNameList(lordBuff)
            if deputy then
            table.insertTable(skills, deputy:getSkillNameList(lordBuff))
            end
            skills = table.filter(skills, function (s)
            local skill = Fk.skills[s]
            return skill and (#skill.attachedKingdom == 0 or table.contains(skill.attachedKingdom, to.kingdom))
            end)
            if #skills > 0 then
            room:handleAddLoseSkills(to, table.concat(skills, "|"), nil, false)
            end

            room:sendLog{ type = "#RevealGeneral", from = to.id, arg =  "mainGeneral", arg2 = general.name }
            local event_data = {["m"] = general}
            if deputy then
            room:sendLog{ type = "#RevealGeneral", from = to.id, arg =  "deputyGeneral", arg2 = deputy.name }
            event_data["d"] = deputy.name
            end
            room.logic:trigger("fk.GeneralAppeared", to, event_data)
        else
            to:drawCards(2,self.name)
            if to.general ~= "hiddenone" and ((to.deputyGeneral ~= "" and to.deputyGeneral ~= "hiddenone") or not to.deputyGeneral ~= "" ) then
                DIYEnterHidden(to)
            end
        end
    end,
}
liuxiu:addSkill(tianshou)
local tianshouu = fk.CreateTriggerSkill{
    name = "ysch4_tianshouu",
    frequency = Skill.Limited,
    mute = true,
    events = {"fk.GeneralAppeared"},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0 then
            if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
            string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil then
                return #table.filter(player.room:getAlivePlayers(),function (cp)
                    return cp:getMark("__hidden_general") ~= 0 or cp:getMark("__hidden_deputy") ~= 0
                end) > 0
            else
                return #table.filter(player.room:getOtherPlayers(target),function (cp)
                    return string.find(Fk:translate(cp.general, "zh_CN"), "刘秀") ~= nil or
                    string.find(Fk:translate(cp.deputyGeneral, "zh_CN"), "刘秀") ~= nil
                end) > 0
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = {}
        local str = "是否发动 天授，令另一名“刘秀”摸两张牌并隐匿"
        if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
        string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil then
            targets = table.map(table.filter(room:getAlivePlayers(),function (cp)
                return cp:getMark("__hidden_general") ~= 0 or cp:getMark("__hidden_deputy") ~= 0
            end),function (cp)
                return cp.id
            end)
            str = "是否发动 天授，令一名隐匿角色弃两张牌并登场"
        else
            targets = table.map(table.filter(room:getOtherPlayers(target),function (cp)
                return string.find(Fk:translate(cp.general, "zh_CN"), "刘秀") ~= nil or
                string.find(Fk:translate(cp.deputyGeneral, "zh_CN"), "刘秀") ~= nil
            end),function (cp)
                return cp.id
            end)
        end
        local tos = room:askForChoosePlayers(player,targets,1,1,str,self.name)
        if #tos > 0 then
            self.cost_data = tos[1]
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data)
        player:broadcastSkillInvoke("ysch4_tianshou")
        room:notifySkillInvoked(player,"ysch4_tianshou","big")
        if string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
        string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil then
            room:askForDiscard(to, 2, 2, true, self.name, false)

            room:handleAddLoseSkills(to, "-hidden_skill&", nil, false, true)
            if Fk.generals[to:getMark("__hidden_general")] then
            to.general = to:getMark("__hidden_general")
            end
            if Fk.generals[to:getMark("__hidden_detouty")] then
            to.deputyGeneral = to:getMark("__hidden_deputy")
            end
            room:setPlayerMark(to, "__hidden_general", 0)
            room:setPlayerMark(to, "__hidden_deputy", 0)
            local general = Fk.generals[to.general]
            local deputy = Fk.generals[to.deputyGeneral]
            to.gender = general.gender
            to.kingdom = general.kingdom
            room:broadcastProperty(to, "gender")
            room:broadcastProperty(to, "general")
            room:broadcastProperty(to, "deputyGeneral")
            room:askForChooseKingdom({to})
            room:broadcastProperty(to, "kingdom")
            
            to.maxHp = to:getGeneralMaxHp()
            to.hp = deputy and math.floor((deputy.hp + general.hp) / 2) or general.hp
            to.shield = math.min(general.shield + (deputy and deputy.shield or 0), 5)
            local changer = Fk.game_modes[room.settings.gameMode]:getAdjustedProperty(to)
            if changer then
            for key, value in pairs(changer) do
                to[key] = value
            end
            end
            room:broadcastProperty(to, "maxHp")
            room:broadcastProperty(to, "hp")
            room:broadcastProperty(to, "shield")

            local lordBuff = to.role == "lord" and to.role_shown == true and #room.players > 4
            local skills = general:getSkillNameList(lordBuff)
            if deputy then
            table.insertTable(skills, deputy:getSkillNameList(lordBuff))
            end
            skills = table.filter(skills, function (s)
            local skill = Fk.skills[s]
            return skill and (#skill.attachedKingdom == 0 or table.contains(skill.attachedKingdom, to.kingdom))
            end)
            if #skills > 0 then
            room:handleAddLoseSkills(to, table.concat(skills, "|"), nil, false)
            end

            room:sendLog{ type = "#RevealGeneral", from = to.id, arg =  "mainGeneral", arg2 = general.name }
            local event_data = {["m"] = general}
            if deputy then
            room:sendLog{ type = "#RevealGeneral", from = to.id, arg =  "deputyGeneral", arg2 = deputy.name }
            event_data["d"] = deputy.name
            end
            room.logic:trigger("fk.GeneralAppeared", to, event_data)
        else
            to:drawCards(2,self.name)
            if to.general ~= "hiddenone" and ((to.deputyGeneral ~= "" and to.deputyGeneral ~= "hiddenone") or not to.deputyGeneral ~= "" ) then
                DIYEnterHidden(to)
            end
        end
    end,

    refresh_events = {"fk.GeneralAppeared"},
    can_refresh = function (self, event, target, player, data)
        return target == player
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:handleAddLoseSkills(player,"-ysch4_tianshouu")
    end,
}
Fk:addSkill(tianshouu)
local zaihui = fk.CreateTriggerSkill{
    name = "ysch4_zaihui$",
    frequency = Skill.Limited,
    events = {"fk.GeneralAppeared"},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and player:usedCardTimes(self.name,Player.HistoryGame) == 0 then
            return string.find(Fk:translate(target.general, "zh_CN"), "刘秀") == nil and
            string.find(Fk:translate(target.deputyGeneral, "zh_CN"), "刘秀") == nil and #table.filter(player.room:getAlivePlayers(),function (cp)
                return cp:getMark("__hidden_general") ~= 0 or cp:getMark("__hidden_deputy") ~= 0
            end) == 0
        end
    end,
    on_use = function (self, event, target, player, data)
        if player.general ~= "hiddenone" and ((player.deputyGeneral ~= "" and player.deputyGeneral ~= "hiddenone") or not player.deputyGeneral ~= "" ) then
            DIYEnterHidden(player)
        end
    end,
}
liuxiu:addSkill(zaihui)
Fk:loadTranslationTable{
    ["ysch4_chengxing"] = "谶兴",
    [":ysch4_chengxing"] = "锁定技，分发手牌前，令所有角色隐匿并获得一个登场后失去的“<a href=':ysch4_tianshouu'>天授</a>”。隐匿角色登场前，可以修改姓名为“刘秀”。一名角色回合结束时，若没有角色隐匿，最后登场的刘秀所在阵营胜利。",
    ["@ysch4_chengxing"] = "谶兴",
    ["#ysch4_chengxing-rename"] = "谶兴：是否将名字修改为“刘秀”",
    ["ysch4_tianshou"] = "天授",
    [":ysch4_tianshou"] = "限定技，“刘秀”登场时，你可以令另一名“刘秀”摸两张牌并隐匿；非“刘秀”登场时，你可以令一名隐匿角色弃两张牌并登场。",
    ["ysch4_tianshouu"] = "天授",
    [":ysch4_tianshouu"] = "限定技，“刘秀”登场时，你可以令另一名“刘秀”摸两张牌并隐匿；非“刘秀”登场时，你可以令一名隐匿角色弃两张牌并登场。",
    ["ysch4_zaihui"] = "再辉",
    [":ysch4_zaihui"] = "主公技，限定技，最后一名隐匿角色登场时，若其不是“刘秀”，你可以隐匿。",

    ["$ysch4_chengxing1"] = "王者受命，其信有符乎？",
    ["$ysch4_chengxing2"] = "仕宦当做执金吾，娶妻当得阴丽华！",
    ["$ysch4_chengxing3"] = "上当天地之心，下为元元所归！修德而为天子。",
    ["$ysch4_tianshou1"] = "贼寇未尽，四面受敌，何遽欲正号位乎？",
    ["$ysch4_tianshou2"] = "制为应天，乐为应人，此所以明天命、昭明德。",
    ["$ysch4_zaihui1"] = "斯皆祖宗之灵、士人之力，朕何足以享斯哉！",
    ["$ysch4_zaihui2"] = "继高祖之休烈、修文武之绝业，欲使社稷复存，炎精更辉！",
    ["~ysch4__liuxiu"] = "日月告凶，不用其行，吾德薄致灾…",
}
local maxiumatie = General:new(extension, "ysch4__maxiumatie", "qun", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__maxiumatie"] = "马休马铁",
    ["#ysch4__maxiumatie"] = "追亡逐北",
    ["designer:ysch4__maxiumatie"] = "小叶子",
    ["cv:ysch4__maxiumatie"] = "佚名",
    ["illustrator:ysch4__maxiumatie"] = "佚名",
}
local quxian = fk.CreateTriggerSkill{
    name = "ysch4_quxian",
    events = {fk.TargetConfirmed, fk.TargetSpecified},
    can_trigger = function(self, event, target, player, data)
        if target == player and player:hasSkill(self) and data.from ~= data.to and data.card.is_damage_card and
        AimGroup:isOnlyTarget(player.room:getPlayerById(data.to), data) then
            return true
        end
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_quxian-prompt:::"..data.card:toLogString()) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        data.additionalEffect = (data.additionalEffect or 0) + 1
        data.extra_data = data.extra_data or {}
        data.extra_data.ysch4_quxian = data.extra_data.ysch4_quxian or {}
        table.insert(data.extra_data.ysch4_quxian,player.id)
    end,

    refresh_events = {fk.CardUseFinished, fk.CardRespondFinished},
    can_refresh = function (self, event, target, player, data)
        local effect = data.responseToEvent
        p(effect)
        return effect and effect.extra_data and effect.extra_data.ysch4_quxian and table.contains(effect.extra_data.ysch4_quxian,player.id)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local effect = data.responseToEvent
        local to = room:getPlayerById(effect.from)
        room:throwCard(room:askForCardChosen(player, to, "he", self.name), self.name, to, player)
    end,
}
maxiumatie:addSkill(quxian)
local jiaoshi = fk.CreateActiveSkill{
    name = "ysch4_jiaoshi",
    anim_type = "support",
    card_num = 0,
    target_num = 1,
    prompt = "#ysch4_jiaoshi",
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = function(self, to_select, selected)
        return false
    end,
    target_filter = function(self, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= Self.id and not Fk:currentRoom():getPlayerById(to_select):isNude()
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        local card = room:askForCardChosen(player, target, "he", self.name)
        room:obtainCard(player.id, card, false, fk.ReasonPrey, player.id, self.name)
        local froms,tos = {target},{player.id}

        local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
            return p ~= target end), Util.IdMapper)
        if #targets > 0 and not player:isKongcheng() then
            local to, id = room:askForChooseCardAndPlayers(player, targets, 1, 1, ".|.|.|hand", "#ysch4_jiaoshi-choose", self.name, true)
            if #to > 0 then
                table.insert(froms,player)
                table.insert(tos,to[1])
                room:obtainCard(to[1], id, false, fk.ReasonGive)
            end
        end

        for _, from in ipairs(froms) do
            local tp = room:askForChoosePlayers(from, table.filter(tos, function(pid) return not from:isProhibited(room:getPlayerById(pid), Fk:cloneCard("slash")) end), 1, 1, "#ysch4_jiaoshi-choose", self.name, false)
            room:useVirtualCard("slash", nil, from, room:getPlayerById(tp[1]), self.name)
        end
    end,
}
maxiumatie:addSkill(jiaoshi)
Fk:loadTranslationTable{
    ["ysch4_quxian"] = "驱险",
    [":ysch4_quxian"] = "你指定或成为伤害牌唯一目标时，你可令此牌多结算一次，此牌被响应后你弃置使用者一张牌。",
    ["#ysch4_quxian-prompt"] = "是否发动 驱险，令 %arg 多结算一次",
    ["ysch4_jiaoshi"] = "角势",
    [":ysch4_jiaoshi"] = "出牌阶段限一次，你可以获得一名其他角色一张牌并可将一张牌交给另一名角色。然后此流程中失去牌的角色视为对一名获得牌的角色使用一张【杀】。",
    ["#ysch4_jiaoshi"] = "是否发动 角势，获得一名其他角色一张牌",
    ["#ysch4_jiaoshi-choose"] = "角势：视为对其中一名角色使用一张【杀】",
}
local ruanzhan = General:new(extension, "ysch4__ruanzhan", "jin", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__ruanzhan"] = "阮瞻",
    ["#ysch4__ruanzhan"] = "何物为我",
    ["designer:ysch4__ruanzhan"] = "黄泉",
    ["cv:ysch4__ruanzhan"] = "佚名",
    ["illustrator:ysch4__ruanzhan"] = "佚名",
}
local yuyuan = fk.CreateTriggerSkill{
    name = "ysch4_yuyuan",
    events = {fk.CardUsing},
    anim_type = "drawcard",
    can_trigger = function (self, event, target, player, data)
        if target == player and player:hasSkill(self.name) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then
            local cards = player:getCardIds(Player.Hand)
            local types,suits = {},{}
            for _, id in ipairs(cards) do
                table.insertIfNeed(types, Fk:getCardById(id).type)
                table.insertIfNeed(suits, Fk:getCardById(id).suit)
            end
            return (#types == 1 or #suits == 1) and #table.filter(player:getCardIds("h"),function (id)
                local card = Fk:getCardById(id)
                return card:getMark("@@ShownCards-inhand") ~= 0
            end) == 0
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        data.additionalEffect = (data.additionalEffect or 0) + 1
        for _, id in ipairs(player:getCardIds("h")) do
            room:setCardMark(Fk:getCardById(id), '@@ShownCards-inhand', 1)
        end
        player:drawCards(player:getHandcardNum(),self.name)
    end,
}
ruanzhan:addSkill(yuyuan)
local yuxu = fk.CreateTriggerSkill{
    name = "ysch4_yuxu",
    anim_type = "control",
    dynamic_desc = function (self, player, lang)
        if player:getMark("@ysch4_yuxu-round") == 0 then
            return "当你获得基本牌后，你可以明置之，然后你：1.弃置非此牌名的明置基本牌；2.此技能于本轮视为“<a href=':ysch4_yuxu_dezhang'>德璋</a>”。"
        else
            return "当你指定或成为伤害牌的目标时，若使用者不处于出牌阶段或其本阶段已使用过同名牌，你须重铸一张明置牌以令此牌无效。"
        end
    end,
    events = {fk.AfterCardsMove,fk.TargetSpecifying, fk.TargetConfirming},
    can_trigger = function(self, event, target, player, data)
        if not player:hasSkill(self) then return false end
        if event == fk.AfterCardsMove then
            if player:getMark("@ysch4_yuxu-round") == 0 then
                local ids = {}
                for _, move in ipairs(data) do
                    if move.toArea == Player.Hand then
                        for _, info in ipairs(move.moveInfo) do
                            if table.contains(player.player_cards[Player.Hand], info.cardId) then
                                Fk:filterCard(info.cardId, player)
                                local c = Fk:getCardById(info.cardId)
                                if c.type == Card.TypeBasic then
                                    table.insertIfNeed(ids, info.cardId)
                                end
                            end
                        end
                    end
                end
                if #ids > 0 then
                    self.cost_data = {cards = ids}
                    return true
                end
            end
        else
            return target == player and player:getMark("@ysch4_yuxu-round") ~= 0 and data.card.is_damage_card and
            (event == fk.TargetSpecifying and data.firstTarget or event == fk.TargetConfirming) and
            #table.filter(player:getCardIds("h"),function (id)
                local card = Fk:getCardById(id)
                return card:getMark("@@ShownCards-inhand") ~= 0
            end) > 0 and
            (player.room:getPlayerById(data.from).phase ~= Player.Play or
            #player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function (e)
                local use = e.data[1]
                return use.from == data.from and use.card.trueName == data.card.trueName
            end, Player.HistoryPhase) > 1)
        end
    end,
    on_cost = function (self, event, target, player, data)
        if player:getMark("@ysch4_yuxu-round") == 0 then
            if player.room:askForSkillInvoke(player,self.name,nil) then
                return true
            end
        else
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.AfterCardsMove then
            local names = {}
            for _, id in ipairs(self.cost_data.cards) do
                room:setCardMark(Fk:getCardById(id), '@@ShownCards-inhand', 1)
                table.insertIfNeed(names,Fk:getCardById(id).name)
            end
            local str = table.concat(table.map(names,function (name)
                return Fk:translate(name,"zh_CN")
            end),"、")
            p(str)
            local choice = room:askForChoice(player,{"#ysch4_yuxu1:::"..str,"#ysch4_yuxu2"},self.name)
            if choice == "#ysch4_yuxu2" then
                room:setPlayerMark(player,"@ysch4_yuxu-round","德璋")
            else
                room:throwCard(table.filter(player:getCardIds("h"),function (id)
                    local card = Fk:getCardById(id)
                    return card:getMark("@@ShownCards-inhand") ~= 0 and not table.contains(names,card.name)
                end),self.name,player)
            end
        else
            local cards = table.filter(player:getCardIds("h"),function (id)
                local card = Fk:getCardById(id)
                return card:getMark("@@ShownCards-inhand") ~= 0
            end)
            local card = room:askForCard(player, 1, 1, false, self.name, false, tostring(Exppattern{ id = cards }),
            "#rfenghou__dezhang-recast:::"..data.card:toLogString())
            room:recastCard(card, player, self.name)
            data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
        end
    end,
}
ruanzhan:addSkill(yuxu)
local yuxu_dezhang = fk.CreateTriggerSkill{
    name = "ysch4_yuxu_dezhang",
    anim_type = "defensive",
    frequency = Skill.Compulsory,
    events = {fk.TargetSpecifying, fk.TargetConfirming},
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(self) and data.card.is_damage_card and
            (event == fk.TargetSpecifying and data.firstTarget or event == fk.TargetConfirming) and
            #table.filter(player:getCardIds("h"),function (id)
                local card = Fk:getCardById(id)
                return card:getMark("@@ShownCards-inhand") ~= 0
            end) > 0 and
            (player.room:getPlayerById(data.from).phase ~= Player.Play or
            #player.room.logic:getEventsOfScope(GameEvent.UseCard, 2, function (e)
                local use = e.data[1]
                return use.from == data.from and use.card.trueName == data.card.trueName
            end, Player.HistoryPhase) > 1)
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = table.filter(player:getCardIds("h"),function (id)
            local card = Fk:getCardById(id)
            return card:getMark("@@ShownCards-inhand") ~= 0
        end)
        local card = room:askForCard(player, 1, 1, false, self.name, false, tostring(Exppattern{ id = cards }),
        "#rfenghou__dezhang-recast:::"..data.card:toLogString())
        room:recastCard(card, player, self.name)
        data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
    end,
}
ruanzhan:addRelatedSkill(yuxu_dezhang)
Fk:loadTranslationTable{
    ["ysch4_yuyuan"] = "语掾",
    [":ysch4_yuyuan"] = "若你手牌类别或花色唯一，你可以明置并翻倍手牌，以令你使用的基本牌或普通锦囊牌多结算一次。",
    ["ysch4_yuxu"] = "语虚",
    [":ysch4_yuxu"] = "当你获得基本牌后，你可以明置之，然后你：1.弃置非此牌名的明置基本牌；2.此技能于本轮视为“<a href=':ysch4_yuxu_dezhang'>德璋</a>”。",
    ["#ysch4_yuxu1"] = "弃置不为%arg的明置基本牌",
    ["#ysch4_yuxu2"] = "此技能本轮视为“德璋”",
    ["@ysch4_yuxu-round"] = "语虚",
    ["ysch4_yuxu_dezhang"] = "德璋",
    [":ysch4_yuxu_dezhang"] = "锁定技，当你指定或成为伤害牌的目标时，若使用者不处于出牌阶段或其本阶段已使用过同名牌，你须重铸一张明置牌以令此牌无效。",
    ["#rfenghou__dezhang-recast"] = "德璋：你需重铸一张明置牌以令此%arg无效",
}
local zhonghui = General:new(extension, "ysch4__zhonghui", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__zhonghui"] = "钟会",
    ["#ysch4__zhonghui"] = "潜蛟窥天",
    ["designer:ysch4__zhonghui"] = "ッ老酒馆的猫",
    ["cv:ysch4__zhonghui"] = "官方",
    ["illustrator:ysch4__zhonghui"] = "biou09",
}
local xieshu = fk.CreateActiveSkill{
    name = "ysch4_xieshu",
    anim_type = "control",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
        return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
    end,
    prompt = "#ysch4_xieshu-prompt",
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])

        local pindian = {
            from = player,
            tos = {target},
            reason = self.name,
            fromCard = nil,
            results = {},
        }
        room:pindian(pindian)
        local winner = pindian.results[target.id].winner
        if winner then
            local num = player:getHandcardNum() + 1
            if winner == player then
                num = target:getHandcardNum() + 1
            end
            if winner:getHandcardNum() ~= num then
                local change = winner:getHandcardNum() - num
                if change > 0 then
                    room:askForDiscard(winner,change,change,false,self.name,false,nil,"#ysch4_xieshu-discard:::"..num)
                else
                    winner:drawCards(-change,self.name)
                end
            else
                local from,to = player,target
                if winner == target then
                    from = target
                    to = player
                end
                room:damage({
                    from = from,
                    to = to,
                    damage = 1,
                    damageType = fk.NormalDamage,
                    skillName = self.name,
                })
            end
        end
    end,
}
local xieshu_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_xieshu_trigger",
    refresh_events = {fk.GameStart,fk.AfterCardsMove},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(xieshu.name)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local max, min
        for _, temp in ipairs(room.alive_players) do
            if table.every(room:getOtherPlayers(temp), function(cp) return cp:getHandcardNum() < temp:getHandcardNum() end) then
                max = temp.id
            end
            if table.every(room:getOtherPlayers(temp), function(cp) return cp:getHandcardNum() > temp:getHandcardNum() end) then
                min = temp.id
            end
            if max and min then
                break
            end
        end
        local lastMax = player:getMark("ysch4_xieshu_max")
        local lastMin = player:getMark("ysch4_xieshu_min")
        local sameMax, sameMin = true, true
        --[[if player:getMark("ysch4_xieshu_max") ~= 0 then
            for _, id in ipairs(lastMax) do
                if not table.contains(max,id) then
                    sameMax = false
                    break
                end
            end
            if sameMax == true then
                for _, id in ipairs(max) do
                    if not table.contains(lastMax,id) then
                        sameMax = false
                        break
                    end
                end
            end
        end
        if player:getMark("ysch4_xieshu_min") ~= 0 then
            for _, id in ipairs(lastMin) do
                if not table.contains(min,id) then
                    sameMin = false
                    break
                end
            end
            if sameMin == true then
                for _, id in ipairs(min) do
                    if not table.contains(lastMin,id) then
                        sameMin = false
                        break
                    end
                end
            end
        end
        if player:getMark("ysch4_xieshu_max") == 0 then sameMax = true end
        if player:getMark("ysch4_xieshu_min") == 0 then sameMin = true end]]--
        if event ~= fk.GameStart then
            if max ~= lastMax then sameMax = false end
            if min ~= lastMin then sameMin = false end
        end
        room:setPlayerMark(player,"ysch4_xieshu_max",max)
        room:setPlayerMark(player,"ysch4_xieshu_min",min)
        if max == nil then
            room:setPlayerMark(player,"@ysch4_xieshu_max",0)
        else
            room:setPlayerMark(player,"@ysch4_xieshu_max",room:getPlayerById(max).general)
            --[[room:setPlayerMark(player,"@ysch4_xieshu_max",table.concat(table.map(max,function (id)
                return Fk:translate(room:getPlayerById(id).general,"zh_CN")
            end)," "))]]--
        end
        if min == nil then
            room:setPlayerMark(player,"@ysch4_xieshu_min",0)
        else
            room:setPlayerMark(player,"@ysch4_xieshu_min",room:getPlayerById(min).general)
            --[[room:setPlayerMark(player,"@ysch4_xieshu_min",table.concat(table.map(min,function (id)
                return Fk:translate(room:getPlayerById(id).general,"zh_CN")
            end)," "))]]--
        end
        if (sameMax == false or sameMin == false) then
            player:setSkillUseHistory("ysch4_xieshu",0,Player.HistoryPhase)
            if not player:isKongcheng() then
                room:askForUseActiveSkill(player,"ysch4_xieshu","#ysch4_xieshu-prompt")
            end
        end
    end,
}
xieshu:addRelatedSkill(xieshu_trigger)
zhonghui:addSkill(xieshu)
Fk:loadTranslationTable{
    ["ysch4_xieshu"] = "挟术",
    [":ysch4_xieshu"] = "出牌阶段限一次，你可以与一名角色拼点，赢的角色将手牌调整至恰好超过没赢的角色，若已是，改为对其造成1点伤害。手牌唯一最多或最少的角色发生变更时，重置此技能并可发动之。",
    ["#ysch4_xieshu-prompt"] = "是否发动 挟术，与一名角色拼点，赢者调整手牌或造成伤害",
    ["#ysch4_xieshu-discard"] = "挟术：将手牌调整至 %arg",
    ["#ysch4_xieshu_trigger"] = "挟术",
    ["@ysch4_xieshu_max"] = "唯一最多",
    ["@ysch4_xieshu_min"] = "唯一最少",

    ["$ysch4_xieshu1"] = "今长缨在手，欲问鼎九州。",
    ["$ysch4_xieshu2"] = "我有佐国之术，可缚苍龙。",
}
local fangdatong = General:new(extension, "ysch4__fangdatong", "qun", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__fangdatong"] = "方大同",
    ["#ysch4__fangdatong"] = "特别的人",
    ["designer:ysch4__fangdatong"] = "君腾天下",
    ["cv:ysch4__fangdatong"] = "方大同",
    ["illustrator:ysch4__fangdatong"] = "未知",
}
local aiaiai = fk.CreateTriggerSkill{
    name = "ysch4_aiaiai",
    events = {fk.CardUseFinished},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            if data.extra_data and data.extra_data.ysch4_aiaiai then return false end
            return not data.card.is_damage_card and data.card.suit == Card.Heart and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
        end
    end,
    dynamic_desc = function (self, player, lang)
        local str = "一张♥非伤害即时牌不以此法结算完后，你可令之于最近时机对对应角色额外结算一次：有角色受到伤害后，该角色；你的回合结束时，你"
        if player:getMark("@@ysch4_aiaiai") ~= 0 then
            str = str .. "；你死亡时，所有角色"
        end
        return str .. "。然后你失去此技能直到此次额外结算完成。"
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_aiaiai-prompt:::"..data.card:toLogString()) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if data.card.id then
            room:setPlayerMark(player,self.name,{target.id,data.card.name})
        else
            room:setPlayerMark(player,self.name,{target.id,data.card.id})
        end
        room:setPlayerMark(player,"@ysch4_aiaiai",data.card:toLogString())
        room:handleAddLoseSkills(player,"-ysch4_aiaiai")
    end,

    refresh_events = {fk.Damaged,fk.TurnEnd,fk.Death},
    can_refresh = function (self, event, target, player, data)
        if player:getMark(self.name) ~= 0 then
            if event == fk.Damaged then
                return true
            elseif event == fk.TurnEnd then
                return target == player
            else
                return target == player and player:getMark("@@ysch4_aiaiai") ~= 0
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local from = player:getMark(self.name)[1]
        local card
        if type(player:getMark(self.name)[2]) == "string" then
            card = Fk:cloneCard(player:getMark(self.name)[2],Card.Heart)
        else
            card = Fk:getCardById(player:getMark(self.name)[2])
        end
        room:setPlayerMark(player,self.name,0)
        room:setPlayerMark(player,"@ysch4_aiaiai",0)
        if card then
            local tos = {target.id}
            if event == fk.Death then
                tos = table.map(room.alive_players, function (cp) return cp.id end)
            end
            room:useCard{
                from = from,
                tos = table.map(tos, function(id) return {id} end),
                card = card,
            }
        end
        room:handleAddLoseSkills(player,"ysch4_aiaiai")
    end,
}
fangdatong:addSkill(aiaiai)
local mengxiangjia = fk.CreateViewAsSkill{
    name = "ysch4_mengxiangjia",
    pattern = ".",
    interaction = function()
        local mark = Self:getTableMark("@$ysch4_mengxiangjia")
        local names,all_names = {}, {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if card:isCommonTrick() and not card.is_derived and not card.is_damage_card and card.suit == Card.Heart then
                table.insertIfNeed(all_names, card.name)
                if not table.contains(mark, id) then
                    table.insertIfNeed(names, card.name)
                end
            end
        end
        return U.CardNameBox {
            choices = U.getViewAsCardNames(Self, "ysch4_mengxiangjia", names, nil),
            all_choices = all_names,
        }
    end,
    view_as = function (self, cards, player)
        if not self.interaction.data then return end
        local card = Fk:cloneCard(self.interaction.data,Card.Heart)
        card.skillName = self.name
        return card
    end,
    after_use = function (self, player, use)
        local room = player.room
        if player.phase ~= Player.NotActive then
            room:setPlayerMark(player,"ysch4_mengxiangjia_1-round",1)
        else
            room:setPlayerMark(player,"ysch4_mengxiangjia_2-round",1)
        end
    end,
    enabled_at_play = function(self, player)
        if player:getMark("@@ysch4_aiaiai") == 0 then
            if player.phase ~= Player.NotActive then
                return player:getMark("ysch4_mengxiangjia_1-round") == 0
            else
                return player:getMark("ysch4_mengxiangjia_2-round") == 0
            end
        end
    end,
    enabled_at_response = function(self, player, response)
        if not response and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and Fk.currentResponsePattern and player:getMark("@@ysch4_aiaiai") == 0 then
            local mark = Self:getTableMark("@$ysch4_mengxiangjia")
            for _, id in ipairs(Fk:getAllCardIds()) do
                local card = Fk:getCardById(id)
                if card:isCommonTrick() and not card.is_derived and not card.is_damage_card and card.suit == Card.Heart and
                Exppattern:Parse(Fk.currentResponsePattern):match(card) then
                    if not table.contains(mark, id) then
                        if player.phase ~= Player.NotActive then
                            return player:getMark("ysch4_mengxiangjia_1-round") == 0
                        else
                            return player:getMark("ysch4_mengxiangjia_2-round") == 0
                        end
                    end
                end
            end
        end
    end,
}
local mengxiangjia_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_mengxiangjia_trigger",
    refresh_events = {fk.CardUsing,fk.CardResponding,fk.AfterCardsMove,fk.CardShown},
    can_refresh = function (self, event, target, player, data)
        if player:hasSkill(mengxiangjia.name) then
            if event == fk.AfterCardsMove then
                for _, move in ipairs(data) do
                    if move.moveVisible then
                        for _, info in ipairs(move.moveInfo) do
                            local card = Fk:getCardById(info.cardId, true)
                            if card:isCommonTrick() and not card.is_damage_card and card.suit == Card.Heart then
                                return true
                            end
                        end
                    end
                end
            elseif event == fk.CardShown then
                for _, id in ipairs(data.cardIds) do
                    local card = Fk:getCardById(id, true)
                    if card:isCommonTrick() and not card.is_damage_card and card.suit == Card.Heart then
                        return true
                    end
                end
            else
                if data.card:isCommonTrick() and not data.card.is_damage_card and data.card.suit == Card.Heart and not data.card:isVirtual() then
                    return true
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark("@$ysch4_mengxiangjia")
        if event == fk.AfterCardsMove then
            for _, move in ipairs(data) do
                if move.moveVisible then
                    for _, info in ipairs(move.moveInfo) do
                        local card = Fk:getCardById(info.cardId, true)
                        if card:isCommonTrick() and not card.is_damage_card and card.suit == Card.Heart then
                            table.insertIfNeed(mark,info.cardId)
                        end
                    end
                end
            end
        elseif event == fk.CardShown then
            for _, id in ipairs(data.cardIds) do
                local card = Fk:getCardById(id, true)
                if card:isCommonTrick() and not card.is_damage_card and card.suit == Card.Heart then
                    table.insertIfNeed(mark,id)
                end
            end
        else
            if data.card:isCommonTrick() and not data.card.is_damage_card and data.card.suit == Card.Heart and not data.card:isVirtual() then
                table.insertIfNeed(mark,data.card.id)
            end
        end
        room:setPlayerMark(player,"@$ysch4_mengxiangjia",mark)
        local cards = {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if card:isCommonTrick() and not card.is_derived and not card.is_damage_card and card.suit == card.Heart then
                if not table.contains(mark, id) then
                    table.insertIfNeed(cards, id)
                end
            end
        end
        if #cards == 0 then
            room:notifySkillInvoked(player,"ysch4_mengxiangjia","big")
            room:setPlayerMark(player,"@@ysch4_aiaiai",1)
        end
    end,
}
mengxiangjia:addRelatedSkill(mengxiangjia_trigger)
fangdatong:addSkill(mengxiangjia)
Fk:loadTranslationTable{
    ["ysch4_aiaiai"] = "爱爱爱",
    [":ysch4_aiaiai"] = "一张<font color='red'>♥</font>非伤害即时牌不以此法结算完后，你可令之于最近时机对对应角色额外结算一次：有角色受到伤害后，该角色；你的回合结束时，你。然后你失去此技能直到此次额外结算完成。",
    ["#ysch4_aiaiai-prompt"] = "是否发动 爱爱爱，令 %arg 可延迟一段时间后额外结算一次",
    ["@ysch4_aiaiai"] = "爱",
    ["@@@ysch4_aiaiai"] = "爱爱爱 梦想家",
    ["ysch4_mengxiangjia"] = "梦想家",
    [":ysch4_mengxiangjia"] = "每轮回合内外各限一次，你可视为使用一张未出现过的<font color='red'>♥</font>非伤害类普通锦囊牌；上述牌均出现过后，在“爱爱爱”增加“你死亡时，所有角色”。",
    ["@$ysch4_mengxiangjia"] = "梦想家",

    ["$ysch4_aiaiai1"] = "你喊出来，我静下来，都是为了爱爱爱",
    ["$ysch4_aiaiai2"] = "可是我有时候宁愿选择留恋不放手",
    ["$ysch4_mengxiangjia"] = "昨天变成了今天，过去变成了现在，未来刚才来",
    ["~ysch4__fangdatong"] = "But the truth telling me That THERE'S NOTHING HE LEFT TO SAY.",
}
local wenyang = General:new(extension, "ysch4__wenyang", "wei", 4, 4, General.Male)--
wenyang.subkingdom = "wu"
Fk:loadTranslationTable{
    ["ysch4__wenyang"] = "文鸯",
    ["#ysch4__wenyang"] = "独骑破军",
    ["designer:ysch4__wenyang"] = "长青",
    ["cv:ysch4__wenyang"] = "官方",
    ["illustrator:ysch4__wenyang"] = "biou09",
}
local chuifeng = fk.CreateViewAsSkill{
    name = "ysch4_chuifeng",
    anim_type = "offensive",
    pattern = "duel",
    prompt = "#ysch4_chuifeng-duel",
    handly_pile = true,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeBasic
    end,
    view_as = function(self, cards)
        if #cards ~= 1 then return end
        local card = Fk:cloneCard("duel")
        card.skillName = self.name
        card:addSubcard(cards[1])
        return card
    end,
    enabled_at_response = function(self, player, response)
        return not response
    end,
}
local chuifeng_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_chuifeng_trigger",
    anim_type = "defensive",
    events = {fk.PreCardEffect},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(chuifeng.name) and data.card.trueName == "slash" and data.to == player.id
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,"ysch4_chuifeng",nil,"#ysch4_chuifeng-change:::"..data.card:toLogString()) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        player:broadcastSkillInvoke("ysch4_chuifeng")
        player.room:changeKingdom(player, "wu", true)
        return true
    end,
}
chuifeng:addRelatedSkill(chuifeng_trigger)
chuifeng:addAttachedKingdom("wei")
wenyang:addSkill(chuifeng)
local chongjian = fk.CreateTriggerSkill{
    name = "ysch4_chongjian",
    anim_type = "control",
    events = {fk.AfterCardUseDeclared},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and data.card.is_damage_card
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_chongjian:::"..data.card:toLogString()) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        data.additionalDamage = (data.additionalDamage or 0) + 1
        local cards = room:askForDiscard(player, 1, 1, true, self.name, true, ".|.|.|.|.|"..data.card:getTypeString(), "#ysch4_chongjian-discard")
        if #cards == 0 then
            player.room:changeKingdom(player, "wei", true)
        end
    end,
}
chongjian:addAttachedKingdom("wu")
wenyang:addSkill(chongjian)
Fk:loadTranslationTable{
    ["ysch4_chuifeng"] = "椎锋",
    [":ysch4_chuifeng"] = "魏势力技，你可以将基本牌当【决斗】使用；你响应【杀】的方式添加改变势力至吴。",
    ["#ysch4_chuifeng-duel"] = "椎锋：你可以将基本牌当【决斗】使用",
    ["#ysch4_chuifeng-change"] = "椎锋：你可以将势力改变至吴抵消%arg",
    ["#ysch4_chuifeng_trigger"] = "椎锋",
    ["ysch4_chongjian"] = "冲坚",
    [":ysch4_chongjian"] = "吴势力技，伤害牌指定目标后，你可以为之助战→造成伤害+1；此次助战方式添加改变势力至魏。",
    ["#ysch4_chongjian"] = "冲坚：你可以为%arg助战→造成伤害+1",
    ["#ysch4_chongjian-discard"] = "冲坚：弃置一张同类型牌，或将势力改变至魏",

    ["$ysch4_chuifeng1"] = "率军冲锋，不惧刀枪所阻！",
    ["$ysch4_chuifeng2"] = "登锋履刃，何妨马革裹尸！",
    ["$ysch4_chongjian1"] = "尔等良将，于我不堪一击！",
    ["$ysch4_chongjian2"] = "此等残兵，破之何其易也！",
}
local yuanfang = General:new(extension, "ysch4__yuanfang", "qun", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__yuanfang"] = "袁方",
    ["#ysch4__yuanfang"] = "孤鹤高嘶",
    ["designer:ysch4__yuanfang"] = "张让",
    ["cv:ysch4__yuanfang"] = "未知",
    ["illustrator:ysch4__yuanfang"] = "未知",
}
local woqi = fk.CreateTriggerSkill{
    name = "ysch4_woqi",
    events = {fk.AfterCardTargetDeclared},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self) and #TargetGroup:getRealTargets(data.tos) == 1 and data.card:isCommonTrick() and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_woqi-prompt::"..target.id..":"..data.card:toLogString()) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
        local prompt = "#ysch4_woqi-ask"
        local extra_data = {bypass_times = false, extraUse = false}
        if target ~= player then
            local use = room:askForUseCard(player, "slash", "slash", "#ysch4_woqi-use", true, {exclusive_targets = {target.id}})
            if use then
                room:useCard(use)
            else
                extra_data.exclusive_targets = {player.id}
                prompt = "#ysch4_woqi-exclusive::"..player.id
            end
        end
        local cards = U.getUniversalCards(room, "t")
        if data.card.is_damage_card then
            cards = table.filter(cards,function (id)
                return not Fk:getCardById(id).is_damage_card
            end)
        else
            cards = table.filter(cards,function (id)
                return Fk:getCardById(id).is_damage_card
            end)
        end
        extra_data.expand_pile = cards
        local use = U.askForUseRealCard(room, target, cards, nil, self.name, prompt,
        extra_data, true, false)
        if use then
            use = {
              card = Fk:cloneCard(use.card.name),
              from = target.id,
              tos = use.tos,
              extraUse = true,
            }
            if extra_data.exclusive_targets then
                use.tos = {{player.id}}
            end
            use.card.skillName = self.name
            room:useCard(use)
        end
    end,
}
yuanfang:addSkill(woqi)
local yinxian_fireAttackSkill = fk.CreateActiveSkill{
    name = "#ysch4_yinxian_fire_attack_skill",
    mute = true,
    prompt = "#fire_attack_skill",
    can_use = Util.CanUse,
    target_num = 1,
    mod_target_filter = function(_, to_select, _, _, _, _)
        local to = Fk:currentRoom():getPlayerById(to_select)
        return not to:isKongcheng()
    end,
    target_filter = Util.TargetFilter,
    on_effect = function(self, room, cardEffectEvent)
        local from = room:getPlayerById(cardEffectEvent.from)
        local to = room:getPlayerById(cardEffectEvent.to)
        if to:isKongcheng() then return end

        local showCard = room:askForCard(to, 1, 1, false, "fire_attack_skill", false, ".|.|.|hand", "#fire_attack-show:" .. from.id)[1]
        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if use_event then
            local use = use_event.data[1]
            use.extra_data = use.extra_data or {}
            use.extra_data.ysch4_yinxian = use.extra_data.ysch4_yinxian or {}
            table.insertIfNeed(use.extra_data.ysch4_yinxian, {to.id, showCard})
        end
        to:showCards(showCard)

        showCard = Fk:getCardById(showCard)
        local cards = room:askForDiscard(from, 1, 1, false, "fire_attack_skill", true,
        ".|.|" .. showCard:getSuitString(), "#fire_attack-discard:" .. to.id .. "::" .. showCard:getSuitString())
        if #cards > 0 then
        room:damage({
            from = from,
            to = to,
            card = cardEffectEvent.card,
            damage = 1,
            damageType = fk.FireDamage,
            skillName = "fire_attack_skill"
        })
        end
    end,
}
Fk:addSkill(yinxian_fireAttackSkill)
local yinxian = fk.CreateTriggerSkill{
    name = "ysch4_yinxian",
    events = {fk.EventPhaseEnd},
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and player.phase == Player.Finish
    end,
    on_cost = function(self, event, target, player, data)
        local to = player.room:askForChoosePlayers(player, table.map(table.filter(player.room:getOtherPlayers(player), function (cp)
            return not cp:isAllNude()
        end),Util.IdMapper), 1, 1,
        "#ysch4_yinxian-choose", self.name, true)
        if #to > 0 then
            self.cost_data = to[1]
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local tos = {self.cost_data}
        for index, _ in ipairs(tos) do
            local to = tos[index]
            local tocp = room:getPlayerById(to)
            local cards = U.askforCardsChosenFromAreas(tocp, tocp, "hej", self.name, nil, nil, false)
            local card = Fk:cloneCard("fire_attack")
            card.skillName = self.name
            card:addSubcards(cards)
            room:useCard{
                from = to ,
                tos = { { player.id} },
                card = card,
                extraUse = true,
            }
            if index == 1 then
                local ret,left,right = {},{},{}
                local temp = player.next
                while temp ~= tocp do
                    if temp:isAlive() then
                        table.insert(right, temp.id)
                    end
                    temp = temp.next
                end
                temp = tocp.next
                while temp ~= player do
                    if temp:isAlive() then
                        table.insert(left, temp.id)
                    end
                    temp = temp.next
                end

                if #left <= #right and #left > 0 then
                    table.insertTable(ret,left)
                end
                if #left >= #right and #right > 0 then
                    table.insertTable(ret,right)
                end

                if #ret > 0 then
                    local froms = room:askForChoosePlayers(player,ret,1,#ret,"#ysch4_yinxian-again",self.name,true)
                    if #froms > 0 then
                        table.insertTable(tos,froms)
                    end
                end
            end
        end
    end,

    refresh_events = {fk.PreCardEffect,fk.CardUseFinished},
    can_refresh = function(self, event, target, player, data)
        return data.card.trueName == "fire_attack" and data.card.skillName == self.name
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        if event == fk.PreCardEffect then
            local card = data.card:clone()
            local c = table.simpleClone(data.card)
            for k, v in pairs(c) do
                card[k] = v
            end
            card.skill = yinxian_fireAttackSkill
            data.card = card
        else
            local suits = {}
            if data.extra_data and data.extra_data.ysch4_yinxian then
                for _, info in ipairs(data.extra_data.ysch4_yinxian) do
                    if info[1] == player.id then
                        table.insertIfNeed(suits, Fk:getCardById(info[2]).suit)
                    end
                end
            end
            if #suits > 0 then
                for _, value in ipairs(suits) do
                    if not table.contains(table.map(data.card.subcards,function (id)
                        return Fk:getCardById(id).suit
                    end),value) then
                        if not target.dead then
                            room:loseHp(target, 1, self.name)
                            break
                        end
                    end
                end
            end
        end
    end,
}
yuanfang:addSkill(yinxian)
Fk:loadTranslationTable{
    ["ysch4_woqi"] = "握奇",
    [":ysch4_woqi"] = "每回合限一次，伤害类/非伤害普通锦囊牌指定唯一目标时，你可以令之无效，然后使用者视为使用另一种牌；若其不为你，你需对其使用一张【杀】，否则此牌仅能指定你为目标。",
    ["#ysch4_woqi-prompt"] = "是否发动 握奇，令%dest使用的%arg无效，然后其视为使用另一种牌",
    ["#ysch4_woqi-use"] = "握奇：对其使用一张【杀】，否则其只能对你使用另一种牌",
    ["#ysch4_woqi-ask"] = "握奇：视为使用一张牌",
    ["#ysch4_woqi-exclusive"] = "握奇：视为对%dest使用一张牌",
    ["ysch4_yinxian"] = "引燹",
    [":ysch4_yinxian"] = "结束阶段，你可以选择一名其他角色，令其将每个区域各一张牌当作【火攻】对你使用；若你展示与这些牌花色均不同的牌，其失去1点体力。然后你可以令其与你之间的任意名角色也如此做。",
    ["#ysch4_yinxian-choose"] = "引燹：你可以令一名其他角色将其每个区域各一张牌当作【火攻】对你使用",
    ["#ysch4_yinxian-again"] = "引燹：你可以令其中任意名角色也如此做",
}
local sangdinuo = General:new(extension, "ysch4__sangdinuo", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__sangdinuo"] = "桑地诺",
    ["#ysch4__sangdinuo"] = "",
    ["designer:ysch4__sangdinuo"] = "梦貘沉眠",
    ["cv:ysch4__sangdinuo"] = "未知",
    ["illustrator:ysch4__sangdinuo"] = "未知",
}
local ziyouzhanqi_viewas1 = fk.CreateViewAsSkill{
    name = "#ysch4_ziyouzhanqi_viewas1",
    handly_pile = true,
    card_filter = function(self, to_select, selected)
        local card = Fk:getCardById(to_select)
        return #selected == 0 and (card.color ~= Card.Red or card.trueName == "jink")
    end,
    view_as = function(self, cards)
        if #cards ~= 1 then return end
        local card = Fk:cloneCard("slash")
        card:addSubcards(cards)
        card.skillName = "ysch4_ziyouzhanqi"
        return card
    end,
}
local ziyouzhanqi_viewas2 = fk.CreateViewAsSkill{
    name = "#ysch4_ziyouzhanqi_viewas2",
    handly_pile = true,
    card_filter = function(self, to_select, selected)
        local card = Fk:getCardById(to_select)
        return #selected == 0 and (card.color ~= Card.Black or card.trueName == "jink")
    end,
    view_as = function(self, cards)
        if #cards ~= 1 then return end
        local card = Fk:cloneCard("slash")
        card:addSubcards(cards)
        card.skillName = "ysch4_ziyouzhanqi"
        return card
    end,
}
Fk:addSkill(ziyouzhanqi_viewas1)
Fk:addSkill(ziyouzhanqi_viewas2)
local ziyouzhanqi = fk.CreateActiveSkill{
    name = "ysch4_ziyouzhanqi",
    switch_skill_name = "ysch4_ziyouzhanqi",
    mute = true,
    card_num = 0,
    card_filter = Util.FalseFunc,
    target_num = 0,
    target_filter = Util.FalseFunc,
    prompt = "#ysch4_ziyouzhanqi-prompt",
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local useSlash = false
        local skill = "#ysch4_ziyouzhanqi_viewas1"
        if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
            room:setPlayerMark(player,MarkEnum.SwithSkillPreName .. self.name,fk.SwitchYang)
            local use = U.askForPlayCard(room,player,nil,".|.|heart,diamond",self.name,"#ysch4_ziyouzhanqi-yang",{bypass_times = true, extraUse = true, bypass_distances = true},true)
            if use then
                room:notifySkillInvoked(player,self.name,"switch")
                room:setPlayerMark(player,MarkEnum.SwithSkillPreName .. self.name,fk.SwitchYin)
                useSlash = true
                room:useCard(use)
            else
                player:setSkillUseHistory(self.name, player:usedSkillTimes(self.name, Player.HistoryGame) - 1, Player.HistoryGame)
            end
        else
            skill = "#ysch4_ziyouzhanqi_viewas2"
            room:setPlayerMark(player,MarkEnum.SwithSkillPreName .. self.name,fk.SwitchYin)
            local use = U.askForPlayCard(room,player,nil,".|.|spade,club",self.name,"#ysch4_ziyouzhanqi-yin",{bypass_times = true, extraUse = true},true)
            if use then
                room:notifySkillInvoked(player,self.name,"switch")
                room:setPlayerMark(player,MarkEnum.SwithSkillPreName .. self.name,fk.SwitchYang)
                useSlash = true
                use.additionalDamage = 1
                room:useCard(use)
            else
                player:setSkillUseHistory(self.name, player:usedSkillTimes(self.name, Player.HistoryGame) - 1, Player.HistoryGame)
            end
        end
        if useSlash and not player.dead then
            local success, dat = room:askForUseActiveSkill(player, skill, skill.."-invoke", true, {bypass_times = true})
            if success and dat then
                local card = Fk.skills[skill]:viewAs(dat.cards)
                local use = {
                    from = player.id,
                    tos = table.map(dat.targets, function(id) return {id} end),
                    card = card,
                    extraUse = true,
                }
                room:useCard(use)
            else
                room:loseHp(player,1,self.name)
            end
        end
    end,
}

sangdinuo:addSkill(ziyouzhanqi)
local siwangwuju = fk.CreateTriggerSkill{
    name = "ysch4_siwangwuju",
    anim_type = "drawcard",
    events = {fk.EnterDying},
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player
    end,
    prompt = "#ysch4_siwangwuju-invoke",
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:throwAllCards("hej")
        player:drawCards(4-player:getHandcardNum(),self.name)
        if room:askForSkillInvoke(player,self.name,nil,"#ysch4_siwangwuju-recover") then
            room:recover({
                who = player,
                num = 1 - player.hp,
                recoverBy = player,
                skillName = self.name,
            })
            room:endTurn()
            while true do
                local use = U.askForPlayCard(room,player,player:getCardIds("h"),".",self.name,"#ysch4_siwangwuju-use",{extraUse = true, bypass_times = true},true)
                if use then
                    room:useCard(use)
                else
                    break
                end
            end
            room:killPlayer{who = player.id}
        end
    end,
}
sangdinuo:addSkill(siwangwuju)
Fk:loadTranslationTable{
    ["ysch4_ziyouzhanqi"] = "自由战旗",
    [":ysch4_ziyouzhanqi"] = "转换技，出牌阶段，你可以①无距离限制使用一张红色牌②使用一张造成伤害+1的黑色牌。结算后你须将一张【闪】或与使用牌颜色不同的牌当【杀】使用，或失去1点体力。",
    ["#ysch4_ziyouzhanqi-prompt"] = "是否发动 自由战旗？",
    ["#ysch4_ziyouzhanqi-yang"] = "自由战旗：你可以无距离限制使用一张红色牌",
    ["#ysch4_ziyouzhanqi-yin"] = "自由战旗：你可以使用一张造成伤害+1的黑色牌",
    ["#ysch4_ziyouzhanqi_viewas1"] = "自由战旗",
    ["#ysch4_ziyouzhanqi_viewas2"] = "自由战旗",
    ["#ysch4_ziyouzhanqi_viewas1-invoke"] = "自由战旗：将一张【闪】或非红色牌当【杀】使用，或失去1点体力。",
    ["#ysch4_ziyouzhanqi_viewas2-invoke"] = "自由战旗：将一张【闪】或非黑色牌当【杀】使用，或失去1点体力。",
    ["ysch4_siwangwuju"] = "死亡无惧",
    [":ysch4_siwangwuju"] = "你进入濒死时，可以弃置区域内所有牌，将手牌摸至四张；也可以再回复体力至1点，结束当前回合，使用任意张手牌，最后死亡。",
    ["#ysch4_siwangwuju-invoke"] = "是否发动 死亡无惧，弃置区域内所有牌，将手牌摸至四张",
    ["#ysch4_siwangwuju-recover"] = "死亡无惧：是否回复体力至1点，然后结束当前回合，使用任意张手牌，最后死亡",
    ["#ysch4_siwangwuju-use"] = "死亡无惧：使用所有手牌，最后你死亡",
}
local JoeKid = General:new(extension, "ysch4__JoeKid", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__JoeKid"] = "乔尼·乔斯达",
    ["#ysch4__JoeKid"] = "想当零",
    ["designer:ysch4__JoeKid"] = "cyc&铝<br>鸣谢：独孤妙妙、zzcclll朱苦力",
    ["cv:ysch4__JoeKid"] = "未知",
    ["illustrator:ysch4__JoeKid"] = "未知",
}
Fk:addQmlMark{
    name = "chongtian",
    how_to_show = function(_, value)
        local roleColor = {
            ["lord"] = "#fd2000",
            ["loyalist"] = "#ec7b2c",
            ["rebel"] = "#00b90f",
            ["renegade"] = "#2e90c7",
        }
        if type(value) == "table" then
            if #value == 1 then
                return table.concat(table.map(value,function (element)
                    local str = Fk:translate(element,"zh_CN")
                    if roleColor[element] then
                        str = "<font color='"..roleColor[element] .. "'>" .. str .. "</font>"
                    end
                    return str
                end),"")
            elseif #value == 2 then
                return table.concat(table.map(value,function (element)
                    local str = Fk:translate(element,"zh_CN")
                    if roleColor[element] then
                        str = "<font color='"..roleColor[element] .. "'>" .. str .. "</font>"
                    end
                    return str
                end)," ")
            elseif #value == 3 then
                return table.concat(table.map(value,function (element)
                    local str = string.sub(Fk:translate(element,"zh_CN"),1,3)
                    if roleColor[element] then
                        str = "<font color='"..roleColor[element] .. "'>" .. str .. "</font>"
                    end
                    return str
                end)," ")
            else
                return table.concat(table.map(value,function (element)
                    local str = string.sub(Fk:translate(element,"zh_CN"),1,3)
                    if roleColor[element] then
                        str = "<font color='"..roleColor[element] .. "'>" .. str .. "</font>"
                    end
                    return str
                end),"")
            end
        end
        if type(value) == "string" then return value end
        return " "
    end,
    qml_path = "",
}
--- 游戏结束检测
---@param room Room
---@param victim? ServerPlayer @ 死亡角色，可以没有
local  function winnerCheck(room, victim)
    local function extraRole(to)
        local ret = to:getMark("@[chongtian]ysch4__chongtian")
        if type(ret) == "string" then return {ret} end
        if type(ret) == "table" and type(ret[1]) == "string" then return ret end
        return {}
    end
    local alive_players = table.filter(room.players, function (p)
        return p ~= victim and not (p.dead and p.rest == 0)
    end)
    -- 没有人存活的话就平局吧
    if #alive_players == 0 then room:gameOver("") return true end
    -- 只剩我了，让我赢呗
    if #alive_players == 1 then room:gameOver(alive_players[1].role) return true end
    local alive_roles = {}
    for _, p in ipairs(alive_players) do
        table.insertIfNeed(alive_roles, p.role)
        local exrole = extraRole(p)
        if exrole then
            table.insertTableIfNeed(alive_roles,exrole)
        end
    end
    local winnerRole
    -- 先检测内奸胜利，若仅有内奸存活(有一张身份是内奸就算内奸)，则内奸胜利
    if table.every(alive_players, function (p)
        return p.role == "renegade" or table.contains(extraRole(p),"renegade")
    end) then
        winnerRole = "renegade"
    -- 如果仅有主忠存活，则主忠胜利
    elseif table.every(alive_players, function (p)
        if p.role == "lord" or p.role == "loyalist" then return true end
        local exrole = extraRole(p)
        return table.contains(exrole,"lord") or table.contains(exrole,"loyalist")
    end) then
        winnerRole = "lord+loyalist"
    -- 若没有主公，则反贼胜利
    elseif not table.contains(alive_roles, "lord") then
        winnerRole = "rebel"
    -- 如果死亡角色为主公，但仍有其他主公存活，发个提示
    elseif victim and (victim.role == "lord" or table.contains(extraRole(victim), "lord")) then
        room:sendLog{type = "#ChongtianStillLord", toast = true}
    end
    if winnerRole then
        -- 若额外身份符合胜利条件，则变为主身份（如果原本就是主公，就不变了，不然主公没了）
        for _, p in ipairs(alive_players) do
            local role = p:getMark("@[chongtian]ysch4__chongtian")
            if type(role) == "string" and string.find(winnerRole, role) and not (string.find(winnerRole, "lord") and p.role == "lord") then
                room:setPlayerProperty(p, "role_shown", true)
                room:setPlayerProperty(p, "role", role)
            elseif type(role) == "table" then
                for _, value in ipairs(role) do
                    if type(value) == "string" and string.find(winnerRole, value) and not (string.find(winnerRole, "lord") and p.role == "lord") then
                        room:setPlayerProperty(p, "role_shown", true)
                        room:setPlayerProperty(p, "role", value)
                        break
                    end
                end
            end
        end
    end
    if winnerRole then
        room:gameOver(winnerRole)
    end
end
local zhenshiraolehaodayiquanne = fk.CreateTriggerSkill{
    name = "ysch4_zhenshiraolehaodayiquanne",
    events = {fk.GameStart,fk.DamageInflicted},
    mute = true,
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            if event == fk.GameStart then
                return Fk:currentRoom():isGameMode("role_mode")
            else
                return target ~= player and data.damage >= target.hp
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        if event == fk.GameStart then
            return Fk:currentRoom():isGameMode("role_mode")
        else
            if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_zhenshiraolehaodayiquanne-prompt::"..target.id) then
               return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
            player:broadcastSkillInvoke(self.name,1)
            room:notifySkillInvoked(player,self.name,"big")
            room:setPlayerMark(player, "@[chongtian]ysch4__chongtian", {"lord","loyalist","rebel","renegade"})
            room:setBanner("@[:]ysch4__chongtian_rule", "ysch4__chongtian_rule")
        else
            player:broadcastSkillInvoke(self.name,table.random({2,3}))
            room:notifySkillInvoked(player,self.name,"special")
            room:damage {
                from = player,
                to = player,
                damage = player.hp,
            }
        end
    end,
}
local chongtian = fk.CreateActiveSkill{
    name = "steam__chongtian",
    prompt = "#steam__chongtian",
    frequency = Skill.Limited,
    card_num = 0,
    min_target_num = 2,
    card_filter = Util.FalseFunc,
    target_filter = Util.TrueFunc,
    can_use = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
        and Fk:currentRoom():isGameMode("role_mode")
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local role_table = room.logic.role_table
        local roles = role_table[#effect.tos]
        if not roles then return end
        roles = table.simpleClone(roles)
        table.shuffle(roles)
        for i, pid in ipairs(effect.tos) do
            local to = room:getPlayerById(pid)
            local mark = to:getTableMark("@[chongtian]ysch4__chongtian")
            table.insert(mark,roles[i])
            room:setPlayerMark(to, "@[chongtian]ysch4__chongtian", mark)
        end
        room:setBanner("@[:]ysch4__chongtian_rule", "ysch4__chongtian_rule")
    end,
}
local chongtian_delay = fk.CreateTriggerSkill{
    name = "#steam__chongtian_delay",
    mute = true,
    global = true,
    events = {fk.BeforeHpChanged},
    can_trigger = function (self, event, target, player, data)
        return target == player and player:getMark("@[chongtian]ysch4__chongtian") ~= 0
        and data.num < 0 and data.num + player.hp < 1
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        local room = player.room
        --room:setBanner("@[:]ysch4__chongtian_rule", "ysch4__chongtian_rule")
        local function extraRole(to)
            local ret = to:getMark("@[chongtian]ysch4__chongtian")
            if type(ret) == "string" then return {ret} end
            if type(ret) == "table" and type(ret[1]) == "string" then return ret end
            return {}
        end
        local role, exrole = player.role, player:getTableMark("@[chongtian]ysch4__chongtian")
        local new_role, lose_role
        local choices = {}
        -- 如果该角色存在且仅存在一张主公身份牌，且其他角色没有主公身份牌，则其不能移除主公身份牌
        p(not (role == "lord" and table.contains(exrole, "lord")))
        p((role == "lord" or table.contains(exrole, "lord")))
        p(table.every(room:getOtherPlayers(player, false), function (cp)
            return cp.role ~= "lord" and not table.contains(extraRole(cp), "lord")
        end))
        if not (role == "lord" and table.contains(exrole, "lord")) and (role == "lord" or table.contains(exrole, "lord")) and
            table.every(room:getOtherPlayers(player, false), function (p)
                return p.role ~= "lord" and not table.contains(extraRole(p), "lord")
            end)
        then
            if role ~= "lord" then
                table.insert(choices,"ChongtianOrigRole:::"..role)
            end
            for _, value in ipairs(exrole) do
                if value ~= "lord" then
                    table.insert(choices,"ChongtianExtraRole:::"..value)
                end
            end
        else
            table.insert(choices,"ChongtianOrigRole:::"..role)
            for _, value in ipairs(exrole) do
                table.insert(choices,"ChongtianExtraRole:::"..value)
            end
        end
        local changeRole = false
        lose_role = room:askForChoice(player, choices, self.name, "#ysch4__chongtian-lose")
        if lose_role:startsWith("ChongtianOrigRole") then
            lose_role = role
            changeRole = true
        else
            new_role = role
            lose_role = string.sub(lose_role,22)
            table.removeOne(exrole,lose_role)
        end
        if changeRole then
            if #exrole > 1 then
                local choose_exrole = {}
                if table.every(room:getOtherPlayers(player, false), function (p)
                    return p.role ~= "lord" and not table.contains(extraRole(p), "lord")
                end) and table.contains(exrole,"lord") then
                    choose_exrole = {"lord"}
                else
                    choose_exrole = exrole
                end
                new_role = room:askForChoice(player, choose_exrole, self.name, "#ysch4__chongtian-change")
                room:setPlayerProperty(player, "role", new_role)
                table.removeOne(exrole, new_role)
                room:setPlayerMark(player, "@[chongtian]ysch4__chongtian", exrole)
            elseif #exrole == 1 then
                new_role = exrole[1]
                room:setPlayerProperty(player, "role", new_role)
                room:setPlayerMark(player, "@[chongtian]ysch4__chongtian", 0)
            else
                room:setPlayerMark(player, "@[chongtian]ysch4__chongtian", 0)
            end
        else
            --[[if table.every(room:getOtherPlayers(player, false), function (p)
                return p.role ~= "lord" and not table.contains(extraRole(p), "lord")
            end) and table.contains(exrole,"lord") then
                table.insert(exrole,role)
                table.removeOne(exrole,"lord")
                new_role = "lord"
                room:setPlayerProperty(player, "role", new_role)
            end]]--
            if #exrole > 0 then
                room:setPlayerMark(player, "@[chongtian]ysch4__chongtian", exrole)
            else
                room:setPlayerMark(player, "@[chongtian]ysch4__chongtian", 0)
            end
        end
        room:sendLog{type = "#ChongtianRemove", from = player.id, arg = lose_role, toast = true}

        -- 检测一下游戏胜利吧！万一赢了呢
        winnerCheck(room)

        -- 为了执行奖惩，暂时将身份改为弃置的身份
        room:setPlayerProperty(player, "role", lose_role)
        local killer = (data.damageEvent or Util.DummyTable).from
        Fk.game_modes[room.settings.gameMode]:deathRewardAndPunish(player, killer)
        room:setPlayerProperty(player, "role", new_role)
        if role == lose_role or changeRole then
            room:setPlayerProperty(player, "role_shown", true)
        end
        data.num = 0
        return true
    end,
}
chongtian:addRelatedSkill(chongtian_delay)
local chongtian_rule = fk.CreateTriggerSkill{
    name = "#steam__chongtian_rule",
    mute = true,
    priority = 0.000001,
    global = true,
    events = {fk.GameOverJudge},
    can_trigger = function (self, event, target, player, data)
        return target == player and player.rest == 0 and player.dead
        -- 若未发放过额外身份，则不修改游戏规则
        and player.room:getBanner("@[:]ysch4__chongtian_rule") ~= nil
    end,
    on_trigger = function (self, event, target, player, data)
        local room = player.room
        --local winnerRole = Fk.game_modes[room.settings.gameMode]:getWinner(player)
    
        winnerCheck(room, player)
    
        -- 停止原游戏规则结算
        return true
    end,
}
chongtian:addRelatedSkill(chongtian_rule)
Fk:addSkill(chongtian)

Fk:addSkill(chongtian_delay)
Fk:addSkill(chongtian_rule)
JoeKid:addSkill(zhenshiraolehaodayiquanne)
local wanmeidehuangjinluoxuan = fk.CreateTriggerSkill{
    name = "ysch4_wanmeidehuangjinluoxuan",
    events = {fk.GameStart,fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and (event == fk.GameStart or target:hasSkill("rfenghou__hujiao"))
    end,
    mute = true,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.GameStart then
            player:broadcastSkillInvoke(self.name,2)
            room:notifySkillInvoked(player,self.name,"big")
            room:changeHero(player, "rfenghou__yyuaN", false, true, true, false, false)
        else
            if player.general ~= "rfenghou__yyuaN" and player.deputyGeneral ~= "rfenghou__yyuaN" then
                player:broadcastSkillInvoke(self.name)
            else
                player:broadcastSkillInvoke(self.name,table.random({1,3}))
            end
            room:notifySkillInvoked(player,self.name,"special")
            local general = table.filter(room.players,function (sp)
                return sp.general == "rfenghou__yyuaN"
            end)
            local deputyGeneral = table.filter(room.players,function (sp)
                return sp.deputyGeneral == "rfenghou__yyuaN"
            end)
            if #general > 0 then
                for _, cp in ipairs(general) do
                    local targets = table.filter(room.alive_players,function (sp) return sp.general ~= "rfenghou__yyuaN" and sp.deputyGeneral ~= "rfenghou__yyuaN" end)
                    if #targets > 0 then
                        local random_cp = table.random(targets)
                        room:changeHero(random_cp, "rfenghou__yyuaN", false, true, true, false, false)
                        local mark = random_cp:getTableMark("@$rfenghou__hujiao")
                        table.insertTableIfNeed(mark,cp:getTableMark("@$rfenghou__hujiao"))
                        if #mark > 0 then
                            room:setPlayerMark(random_cp,"@$rfenghou__hujiao",mark)
                        else
                            room:setPlayerMark(random_cp,"@$rfenghou__hujiao",0)
                        end
                        if cp.deputyGeneral then
                            room:changeHero(cp, cp.deputyGeneral, false, false, true, false, false)
                            room:changeHero(cp, "", false, true, true, false, false)
                        else
                            room:changeHero(cp, "blank_shibing", false, false, true, false, false)
                        end
                        room:setPlayerMark(cp,"@$rfenghou__hujiao",0)
                    end
                end
            end
            if #deputyGeneral > 0 then
                for _, cp in ipairs(deputyGeneral) do
                    local targets = table.filter(room.alive_players,function (sp) return sp.general ~= "rfenghou__yyuaN" and sp.deputyGeneral ~= "rfenghou__yyuaN" end)
                    if #targets > 0 then
                        local random_cp = table.random(targets)
                        room:changeHero(random_cp, "rfenghou__yyuaN", false, true, true, false, false)
                        local mark = random_cp:getTableMark("@$rfenghou__hujiao")
                        table.insertTableIfNeed(mark,cp:getTableMark("@$rfenghou__hujiao"))
                        if #mark > 0 then
                            room:setPlayerMark(random_cp,"@$rfenghou__hujiao",mark)
                        else
                            room:setPlayerMark(random_cp,"@$rfenghou__hujiao",0)
                        end
                        room:changeHero(cp, "", false, true, true, false, false)
                        room:setPlayerMark(cp,"@$rfenghou__hujiao",0)
                    end
                end
            end
        end
    end,
}
if not Fk.skills["rfenghou__hujiao"] then
    local hujiao = fk.CreateTriggerSkill{
        name = "rfenghou__hujiao",
        anim_type = "control",
        events = {fk.PreCardUse, fk.EventPhaseStart},
        can_trigger = function(self, event, target, player, data)
            if target == player and player:hasSkill(self) then
                if event == fk.PreCardUse then
                return (player.phase == Player.Play or table.contains(data.card.skillNames, self.name)) and data.tos
                elseif event == fk.EventPhaseStart then
                return player.phase == Player.Finish and
                    table.find(player:getTableMark("@$rfenghou__hujiao"), function (name)
                    local card = Fk:cloneCard(name)
                    card.skillName = self.name
                    return card.type ~= Card.TypeEquip and card.sub_type ~= Card.SubtypeDelayedTrick and
                        player:canUse(card, {bypass_distances = true, bypass_times = true})
                    end)
                end
            end
        end,
        on_cost = function (self, event, target, player, data)
            if event == fk.PreCardUse then
                if table.contains(data.card.skillNames, self.name) then
                return true
                else
                return player.room:askForSkillInvoke(player, self.name, nil, "#rfenghou__hujiao-invoke:::"..data.card:toLogString())
                end
            elseif event == fk.EventPhaseStart then
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            if event == fk.PreCardUse then
                if player.phase == Player.Play then
                local mark = player:getTableMark("@$rfenghou__hujiao")
                table.insertIfNeed(mark, data.card.name)
                room:setPlayerMark(player, "@$rfenghou__hujiao", mark)
                end
                local targets = {}
                for _, orig_to in ipairs(data.tos) do
                for _, p in ipairs(room.alive_players) do
                    if not player:isProhibited(p, data.card) and
                    (data.card.sub_type == Card.SubtypeDelayedTrick or data.card.skill:modTargetFilter(p.id, {}, player, data.card, false)) then
                    local ho_spair_check = true
                    if #orig_to > 1 then
                        --target_filter check, for collateral, diversion...
                        local ho_spair_target = {p.id}
                        for i = 2, #orig_to, 1 do
                        local c_pid = orig_to[i]
                        if not data.card.skill:modTargetFilter(c_pid, ho_spair_target, player, data.card, true) then
                            ho_spair_check = false
                            break
                        end
                        table.insert(ho_spair_target, c_pid)
                        end
                    end
                    if ho_spair_check then
                        table.insert(targets, p.id)
                    end
                    end
                end
                end
                if #targets > 0 then
                local random_target = table.random(targets)
                if #TargetGroup:getRealTargets(data.tos) == 1 then
                    if #targets > 1 then
                    for i = 1, 2, 1 do
                        for _, p in ipairs(room:getAllPlayers()) do
                        if table.contains(targets, p.id) then
                            room:setEmotion(p, "./image/anim/selectable")
                            room:notifyMoveFocus(p, self.name)
                            room:delay(300)
                        end
                        end
                    end
                    for _, p in ipairs(room:getAllPlayers()) do
                        if table.contains(targets, p.id) then
                        room:setEmotion(p, "./image/anim/selectable")
                        room:delay(600)
                        if p.id == random_target then
                            room:doIndicate(data.from, {random_target})
                            break
                        end
                        end
                    end
                    end
                    data.tos[1][1] = random_target
                else
                    local new_targets = table.random(targets, math.random(1, #TargetGroup:getRealTargets(data.tos)))
                    for i = 1, #data.tos, 1 do
                    if i <= #new_targets then
                        data.tos[i][1] = new_targets[i]
                    else
                        data.tos[i] = nil
                    end
                    end
                end
                else
                data.tos = {}
                end
            elseif event == fk.EventPhaseStart then
                local all_names = table.simpleClone(player:getTableMark("@$rfenghou__hujiao"))
                local names, tmp = {}, {}
                for _, name in ipairs(all_names) do
                if not tmp[name] then
                    table.insert(names, name)
                    tmp[name] = true
                end
                end
                for _, name in ipairs(names) do
                if player.dead then return end
                local card = Fk:cloneCard(name)
                card.skillName = self.name
                if card.type ~= Card.TypeEquip and card.sub_type ~= Card.SubtypeDelayedTrick and
                    player:canUse(card, {bypass_distances = true, bypass_times = true}) then
                    if card.multiple_targets and card.skill.min_target_num == 0 then
                    room:useCard{
                        from = player.id,
                        card = card,
                        extraUse = true,
                    }
                    else
                    room:useCard{
                        from = player.id,
                        tos = {{player:getNextAlive().id}},
                        card = card,
                        extraUse = true,
                    }
                    end
                end
                end
            end
        end,
    }
    Fk:addSkill(hujiao)
    Fk:loadTranslationTable{
        ["rfenghou__hujiao"] = "胡搅",
        [":rfenghou__hujiao"] = "出牌阶段，你使用牌时，可令之随机指定目标。结束阶段，你依次视为使用本局你使用过的“胡搅”牌每牌名各一张，且均须触发“胡搅”。",
        ["#rfenghou__hujiao-invoke"] = "胡搅：是否令%arg随机指定目标？",
        ["@$rfenghou__hujiao"] = "胡搅",
    }
end
JoeKid:addSkill(wanmeidehuangjinluoxuan)
local JoeKid_win = fk.CreateTriggerSkill{name = "ysch4__JoeKid_win_audio",}
JoeKid_win.package = extension
Fk:addSkill(JoeKid_win)
Fk:loadTranslationTable{
    ["ysch4_zhenshiraolehaodayiquanne"] = "真是绕了好大一圈呢",
    [":ysch4_zhenshiraolehaodayiquanne"] = "游戏开始时，你对自己“<a href=':ysch4__chongtian'>冲天</a>”四种身份牌。其他角色受到致命伤害时，你可先对自己造成致命伤害。",
    ["#ysch4_zhenshiraolehaodayiquanne-prompt"] = "真是绕了好大一圈呢：%dest即将受到致命伤害，是否先对自己造成致命伤害",
    ["ysch4_wanmeidehuangjinluoxuan"] = "完美的黄金螺旋",
    [":ysch4_wanmeidehuangjinluoxuan"] = "游戏开始时，你将“yyuaN低调的温柔胖宝宝”置为副将。有“<a href=':rfenghou__hujiao'>胡搅</a>”的角色回合结束时，你随机移动“yyuaN低调的温柔胖宝宝”和“胡搅”记录。",
    [":ysch4__chongtian"] = "限定技，出牌阶段，若为身份模式，你可以为至少两名角色分发一张额外身份牌，并将此身份牌亮出，其体力值扣减至1以下前须防止之，并弃置额外身份牌或原身份牌，将剩余身份牌作为身份，然后令伤害来源执行被弃置身份牌对应的奖惩。",
    ["@[chongtian]ysch4__chongtian"] = "冲天",
    ["@[:]ysch4__chongtian_rule"] = "额外身份",
    ["ysch4__chongtian_rule"] = "冲天",
    [":ysch4__chongtian_rule"] = "冲天发放身份牌时，根据选择的人数，取对应人数身份局的身份牌配置随机发放。"..
    "<br>当一名角色即将被移去身份牌时，若其有主公身份牌，且未有其他角色有主公身份牌，则其不能移除主公身份牌。"..
    "<br>若游戏结束条件被满足时，存在拥有两张身份牌的角色，其身份牌其中之一属于获胜阵营，其即可获胜。"..
    "<br>仅有内奸存活时，所有内奸均胜利。有多个主公存活时，无法结束游戏。",
    ["#ChongtianRemove"] = "%from 弃置了 %arg 身份牌",
    ["#ChongtianStillLord"] = "<b>仍有主公存活，无法结束游戏！</b>",
    ["#ysch4__chongtian-lose"] = "冲天：请丢弃一张身份牌，令伤害来源执行击杀此身份的奖惩",
    ["#ysch4__chongtian-change"] = "冲天：请选择一张身份牌作为显示身份",
    ["ChongtianOrigRole"] = "原身份(%arg)",
    ["ChongtianExtraRole"] = "额外身份(%arg)",
    ["#steam__chongtian_delay"] = "冲天",
    ["#steam__chongtian_rule"] = "冲天",

    ["$ysch4_zhenshiraolehaodayiquanne1"] = "我现在还只是负数，想成为零啊！",
    ["$ysch4_zhenshiraolehaodayiquanne2"] = "就在刚才明白了，应该射击的地方，那就是我自己！",
    ["$ysch4_zhenshiraolehaodayiquanne3"] = "真的，真的是绕了好大一圈啊。",
    ["$ysch4_wanmeidehuangjinluoxuan1"] = "他妈的你在干什么！",
    ["$ysch4_wanmeidehuangjinluoxuan2"] = "慢步舞者！回来！",
    ["$ysch4_wanmeidehuangjinluoxuan3"] = "回旋变成“洞穴”也不会死的！",
    ["~ysch4__JoeKid"] = "永别了，杰洛。永别了，杰洛……",
    ["ysch4__JoeKid_win_audio"] = "胜利语音",
    ["$ysch4__JoeKid_win_audio"] = "永不停息的回旋，欧拉欧拉欧拉欧拉，完美的黄金回旋！",
}
local lishunchen = General:new(extension, "ysch4__lishunchen", "ghan", 5, 5, General.Male)--
Fk:loadTranslationTable{
    ["ghan"] = "韩",
    ["ysch4__lishunchen"] = "李舜臣",
    ["#ysch4__lishunchen"] = "残月照弓刀",
    ["designer:ysch4__lishunchen"] = "苍苍苍淇",
    ["cv:ysch4__lishunchen"] = "未知",
    ["illustrator:ysch4__lishunchen"] = "未知",
}
local bisijisheng = fk.CreateTriggerSkill{
    name = "ysch4_bisijisheng",
    frequency = Skill.Limited,
    mute = true,
    events = {fk.DamageCaused,fk.DamageInflicted},
    dynamic_desc =function (self, player, lang)
        local mark = type(player:getMark(self.name.."Frequency")) == "string" and player:getMark(self.name.."Frequency") or "LimitedSkill"
        local str = Fk:translate(mark,"zh_CN").."，"
        if mark == "OrdinarySkill" then
            str = ""
        end
        str = str .. "当你造成或受到伤害时，你"
        if mark == "SwitchSkill" then
            local index = getSwitchState(player,self.name)
            if index == 1 then
                str = str.."<font color='#6fb8cc'>①令伤害来源手牌数向你体力值调整3；</font>"
            else
                str = str.."①令伤害来源手牌数向你体力值调整3；"
            end
            if index == 2 then
                str = str.."<font color='#6fb8cc'>②令伤害来源摸2张牌并防止之；</font>"
            else
                str = str.."②令伤害来源摸2张牌并防止之；"
            end
            if index == 3 then
                str = str.."<font color='#6fb8cc'>③令受伤角色手牌均视为【水淹七军】直至有角色体力值或手牌数变为1。</font>"
            else
                str = str.."③令受伤角色手牌均视为【水淹七军】直至有角色体力值或手牌数变为1。"
            end
        else
            str = str .. "①令伤害来源手牌数向你体力值调整3；②令伤害来源摸2张牌并防止之；③令受伤角色手牌均视为【水淹七军】直至有角色体力值或手牌数变为1。"
        end
        if mark == "LimitedSkill" or mark == "ReadySkill" then
            str = str .. "然后你摸取此次发动项数张牌。"
        else
            str = str .. "然后你重铸此次发动项数张牌。"
        end
        return str
    end,
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) and target == player then
            local mark = type(player:getMark(self.name.."Frequency")) == "string" and player:getMark(self.name.."Frequency") or "LimitedSkill"
            if mark == "LimitedSkill" then
                return player:usedSkillTimes(self.name,Player.HistoryGame) == 0
            elseif mark == "ReadySkill" then
                return player:getMark("@@rfenghou_readying:::"..self.name) == 0
            elseif mark == "SwitchSkill" then
                if getSwitchState(player,self.name) == 3 then
                    return data.to and not data.to.dead
                elseif getSwitchState(player,self.name) == 2 then
                    return data.from and not data.from.dead
                elseif getSwitchState(player,self.name) == 1 then
                    return data.from and not data.from.dead and data.from:getHandcardNum() ~= player.hp
                end
            else
                return true
            end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local mark = type(player:getMark(self.name.."Frequency")) == "string" and player:getMark(self.name.."Frequency") or "LimitedSkill"
        local index = getSwitchState(player,self.name) or 1
        local anim_type = "special"
        if mark == "LimitedSkill" then
            anim_type = "big"
        elseif mark == "SwitchSkill" then
            anim_type = "switch"
        end
        room:notifySkillInvoked(player,self.name,anim_type)
        if mark ~= "SwitchSkill" then
            local choices, all_choices = {}, {"#ysch4_bisijisheng1","#ysch4_bisijisheng2","#ysch4_bisijisheng3"}
            if data.from and not data.from.dead then
                if data.from:getHandcardNum() ~= player.hp then table.insert(choices,all_choices[1]) end
                table.insert(choices,all_choices[2])
            end
            if data.to and not data.to.dead then table.insert(choices,all_choices[3]) end
            local choice = room:askForChoice(player,choices,self.name,"#ysch4_bisijisheng-prompt",true,all_choices)
            index = math.tointeger(choice[#choice]) or 1
        end
        local cancelDamage = false
        if index == 1 then
            if data.from:getHandcardNum() > player.hp then
                room:askForDiscard(player,3,3,false,self.name,false,nil)
            elseif data.from:getHandcardNum() < player.hp then
                data.from:drawCards(3,self.name)
            end
        end
        if index == 2 then
            data.from:drawCards(2,self.name)
            cancelDamage = true
        end
        if index == 3 then
            for _, id in ipairs(data.to:getCardIds("h")) do
                room:setCardMark(Fk:getCardById(id), "@@ysch4_bisijisheng-inhand", 1)
                Fk:filterCard(id, data.to)
            end
        end
        local recastCard = true
        if mark ~= "LimitedSkill" then
            player:setSkillUseHistory(self.name,0,Player.HistoryGame)
        else
            recastCard = false
        end
        if mark ~= "ReadySkill" then
            room:setPlayerMark(player,"@@rfenghou_readying:::"..self.name,0)
        else
            room:setPlayerMark(player,"@@rfenghou_readying:::"..self.name,1)
            recastCard = false
        end
        if mark == "SwitchSkill" then
            changeSwitchState(player,self.name,true)
        end
        if recastCard then
            local cards = player:getCardIds("he")
            if #cards > index then
               cards = room:askForCard(player,index,index,true,self.name,false,nil,"#ysch4_bisijisheng-recast:::"..index) 
            end
            room:recastCard(cards,player,self.name)
        else
            player:drawCards(index,self.name)
        end
        if cancelDamage then
            return true
        end
    end,
    on_acquire = function (self, player, is_start)
        local mark = type(player:getMark(self.name.."Frequency")) == "string" and player:getMark(self.name.."Frequency") or "LimitedSkill"
        player.room:setPlayerMark(player,self.name.."Frequency",mark)
        player.room:setPlayerMark(player,"@"..self.name.."Frequency",mark)
    end,
    on_lose = function (self, player, is_death)
        player.room:setPlayerMark(player,"@"..self.name.."Frequency",0)
    end,

    refresh_events = {fk.AfterCardsMove,fk.HpChanged,fk.AfterSkillEffect},
    can_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.AfterSkillEffect then
            local mark = type(player:getMark(self.name.."Frequency")) == "string" and player:getMark(self.name.."Frequency") or "LimitedSkill"
            return target == player and mark ~= "ReadySkill"
        end
        if #table.filter(room.alive_players,function (cp)
            return cp:getMark("@ysch4_bisijisheng-drowning") ~= 0
        end) > 0 then
            if event == fk.AfterCardsMove then
                for _, move in ipairs(data) do
                    local temp = room:getPlayerById(move.to)
                    if temp and temp:getHandcardNum() == 1
                    and move.toArea == Card.PlayerHand then
                        return true
                    end
                    temp = room:getPlayerById(move.from)
                    if temp and temp:getHandcardNum() == 1
                    and table.find(move.moveInfo, function (info) return info.fromArea == Card.PlayerHand end) then
                        return true
                    end
                end
            elseif event == fk.HpChanged then
                return target.hp == 1
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.AfterSkillEffect then
            room:setPlayerMark(player,"@@rfenghou_readying:::"..self.name,0)
        else
            for _, cp in ipairs(room.alive_players) do
                for _, id in ipairs(cp:getCardIds("h")) do
                    room:setCardMark(Fk:getCardById(id), "@@ysch4_bisijisheng-inhand", 0)
                    Fk:filterCard(id, cp)
                end
            end
        end
    end,
}
local bisijisheng_filter = fk.CreateFilterSkill{
    name = "#ysch4_bisijisheng_filter",
    card_filter = function(self, card, player)
        return card:getMark("@@ysch4_bisijisheng-inhand") > 0
    end,
    view_as = function(self, card)
        return Fk:cloneCard("ysch_Al__drowning", card.suit, card.number)
    end,
}
bisijisheng:addRelatedSkill(bisijisheng_filter)
lishunchen:addSkill(bisijisheng)
--bisijisheng.RfenghouReadySkill = true
local shanhedongse = fk.CreateTriggerSkill{
    name = "ysch4_shanhedongse",
    anim_type = "switch",
    events = {fk.AfterCardsMove,fk.HpChanged},
    dynamic_desc =function (self, player, lang)
        local mark = type(player:getMark(self.name.."Frequency")) == "string" and player:getMark(self.name.."Frequency") or "SwitchSkill"
        local str = Fk:translate(mark,"zh_CN").."，"
        if mark == "OrdinarySkill" then
            str = ""
        end
        if mark == "SwitchSkill" then
            local index = getSwitchState(player,self.name)
            if index == 1 then
                str = str.."<font color='#6fb8cc'>①若你手牌数为全场最大，“必死即生”改为“转换技”；</font>"
            else
                str = str.."①若你手牌数为全场最大，“必死即生”改为“转换技”；"
            end
            if index == 2 then
                str = str.."<font color='#6fb8cc'>②若你体力值为全场最小，“必死即生”改为“蓄势技”；</font>"
            else
                str = str.."②若你体力值为全场最小，“必死即生”改为“蓄势技”；"
            end
            if index == 3 then
                str = str.."<font color='#6fb8cc'>③若你手牌数与体力值均为全场唯一，你删除你技能标签。</font>"
            else
                str = str.."③若你手牌数与体力值均为全场唯一，你删除你技能标签。"
            end
        else
            str = str .. "①若你手牌数为全场最大，“必死即生”改为“转换技”；②若你体力值为全场最小，“必死即生”改为“蓄势技”；③若你手牌数与体力值均为全场唯一，你删除你技能标签。"
        end
        return str .. "然后你受到一点你的雷电伤害，若满足他项条件，此次将“受到”改为“分配”。"
    end,
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            local room = player.room
            local index = getSwitchState(player,self.name)
            self.cost_data = 0
            if event == fk.AfterCardsMove then
                for _, move in ipairs(data) do
                    if move.to and move.to == player.id and move.toArea == Player.Hand then
                        local to = player.room:getPlayerById(move.to)
                        if table.contains(player.room:getTag("hcnm_max") or {}, move.to) and not to.dead and table.contains({0,1},index) then
                            if player:getMark("ysch4_shanhedongse_1") ~= 1 and player:getMark("ysch4_bisijishengFrequency") ~= "SwitchSkill" then
                                room:setPlayerMark(player,"ysch4_shanhedongse_1",1)
                                self.cost_data = 1
                            end
                        else
                            room:setPlayerMark(player,"ysch4_shanhedongse_1",0)
                        end
                        if table.contains({0,3},index) and table.every(room:getOtherPlayers(player),function (cp)
                            return cp:getHandcardNum() ~= player:getHandcardNum() and cp.hp ~= player.hp
                        end) then
                            if player:getMark("ysch4_shanhedongse_3") ~= 1 and
                            (player:getMark("ysch4_bisijishengFrequency") ~= "OrdinarySkill" or player:getMark("ysch4_shanhedongseFrequency") ~= "OrdinarySkill") then
                                room:setPlayerMark(player,"ysch4_shanhedongse_3",1)
                                self.cost_data = 3
                            end
                        else
                            room:setPlayerMark(player,"ysch4_shanhedongse_3",0)
                        end
                    end
                end
                if not table.contains(player.room:getTag("hcnm_max") or {}, player.id) then
                    room:setPlayerMark(player,"ysch4_shanhedongse_1",0)
                else
                    room:setPlayerMark(player,"ysch4_shanhedongse_1",1)
                end
                if not table.every(room:getOtherPlayers(player),function (cp)
                    return cp:getHandcardNum() ~= player:getHandcardNum() and cp.hp ~= player.hp
                end) then
                    room:setPlayerMark(player,"ysch4_shanhedongse_3",0)
                else
                    room:setPlayerMark(player,"ysch4_shanhedongse_3",1)
                end
            else
                if target == player then
                    if table.contains({0,2},index) and table.every(room:getOtherPlayers(player),function (cp)
                        return cp.hp >= player.hp
                    end) then
                        if player:getMark("ysch4_shanhedongse_2") ~= 1 and player:getMark("ysch4_bisijishengFrequency") ~= "ReadySkill" then
                            room:setPlayerMark(player,"ysch4_shanhedongse_2",1)
                            self.cost_data = 2
                        end
                    else
                        room:setPlayerMark(player,"ysch4_shanhedongse_2",0)
                    end
                    if table.contains({0,3},index) and table.every(room:getOtherPlayers(player),function (cp)
                        return cp:getHandcardNum() ~= player:getHandcardNum() and cp.hp ~= player.hp
                    end) then
                        if player:getMark("ysch4_shanhedongse_3") ~= 1 and
                        (player:getMark("ysch4_bisijishengFrequency") ~= "OrdinarySkill" or player:getMark("ysch4_shanhedongseFrequency") ~= "OrdinarySkill") then
                            room:setPlayerMark(player,"ysch4_shanhedongse_3",1)
                            self.cost_data = 3
                        end
                    else
                        room:setPlayerMark(player,"ysch4_shanhedongse_3",0)
                    end
                end
                if not table.every(room:getOtherPlayers(player),function (cp)
                    return cp.hp >= player.hp
                end) then
                    room:setPlayerMark(player,"ysch4_shanhedongse_2",0)
                else
                    room:setPlayerMark(player,"ysch4_shanhedongse_2",1)
                end
                if not table.every(room:getOtherPlayers(player),function (cp)
                    return cp:getHandcardNum() ~= player:getHandcardNum() and cp.hp ~= player.hp
                end) then
                    room:setPlayerMark(player,"ysch4_shanhedongse_3",0)
                else
                    room:setPlayerMark(player,"ysch4_shanhedongse_3",1)
                end
            end
            if self.cost_data ~= 0 then
                return true
            end
        end
    end,
    on_cost = Util.TrueFunc,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local index = getSwitchState(player,self.name)
        local source = false
        if index ~= 0 then
            changeSwitchState(player,self.name,true)
        end
        if self.cost_data == 1 then
            if getSwitchState(player,"ysch4_bisijisheng") == 0 then
                setSwitchState(player,"ysch4_bisijisheng",1,3)
            end
            room:setPlayerMark(player,"@@rfenghou_readying:::ysch4_bisijisheng",0)
            room:setPlayerMark(player,"ysch4_bisijishengFrequency","SwitchSkill")
            room:setPlayerMark(player,"@ysch4_bisijishengFrequency","SwitchSkill")
            if table.every(room:getOtherPlayers(player),function (cp)
                return cp.hp >= player.hp
            end) or table.every(room:getOtherPlayers(player),function (cp)
                return cp:getHandcardNum() ~= player:getHandcardNum() and cp.hp ~= player.hp
            end) then
                source = true
            end
        elseif self.cost_data == 2 then
            room:setPlayerMark(player,"ysch4_bisijishengFrequency","ReadySkill")
            room:setPlayerMark(player,"@ysch4_bisijishengFrequency","ReadySkill")
            if table.contains(player.room:getTag("hcnm_max") or {}, player.id) or table.every(room:getOtherPlayers(player),function (cp)
                return cp:getHandcardNum() ~= player:getHandcardNum() and cp.hp ~= player.hp
            end) then
                source = true
            end
            room:handleAddLoseSkills(player, "rfenghou_ready_skill&", nil, false, true)
        else
            room:setPlayerMark(player,"@@rfenghou_readying:::ysch4_bisijisheng",0)
            for _, value in ipairs({"ysch4_bisijisheng","ysch4_shanhedongse"}) do
                room:setPlayerMark(player,value.."Frequency","OrdinarySkill")
                room:setPlayerMark(player,"@"..value.."Frequency","OrdinarySkill")
            end
            removeSwitchSkill(player, self.name)
            if table.every(room:getOtherPlayers(player),function (cp)
                return cp.hp >= player.hp
            end) or table.contains(player.room:getTag("hcnm_max") or {}, player.id) then
                source = true
            end
        end
        if not player.dead then
            if source == false then
                room:damage { from = player, to = player, damage = 1, damageType = fk.ThunderDamage }
            else
                local to = room:askForChoosePlayers(player, table.map(room:getAllPlayers(), Util.IdMapper), 1, 1,
                "#ysch4_shanhedongse_damage", self.name, false)
                if #to > 0 then
                    room:damage{
                        from = player,
                        to = room:getPlayerById(to[1]),
                        damage = 1,
                        damageType = fk.ThunderDamage,
                        skillName = self.name,
                    }
                end
            end
        end
    end,

    on_acquire = function (self, player, is_start)
        setSwitchState(player,self.name,1,3)
    end,
    on_lose = function (self, player, is_death)
        removeSwitchSkill(player, self.name)
    end
}
lishunchen:addSkill(shanhedongse)
Fk:loadTranslationTable{
    ["ysch4_bisijisheng"] = "必死即生",
    [":ysch4_bisijisheng"] = "限定技，当你造成或受到伤害后，你令①伤害来源手牌数向你体力值调整3；②伤害来源摸2张牌并防止之；③受伤角色当前手牌均视为【水淹七军】直至有角色体力值或手牌数变为1。然后你重铸此次发动项数张牌，若此技能将行置，此次将“重铸”改为“摸取”。",
    ["#ysch4_bisijisheng-prompt"] = "必死即生：请选择一项执行",
    ["#ysch4_bisijisheng1"] = "①",
    [":#ysch4_bisijisheng1"] = "令伤害来源手牌数向你体力值调整3",
    ["#ysch4_bisijisheng2"] = "②",
    [":#ysch4_bisijisheng2"] = "令伤害来源摸2张牌并防止之",
    ["#ysch4_bisijisheng3"] = "③",
    [":#ysch4_bisijisheng3"] = "令受伤角色手牌均视为【水淹七军】直至有角色体力值或手牌数变为1。",
    ["#ysch4_bisijisheng-recast"] = "必死即生：请重铸 %arg 张牌",
    ["@ysch4_bisijishengFrequency"] = "必死即生",
    ["@@ysch4_bisijisheng-inhand"] = "必死即生",
    ["#ysch4_bisijisheng_filter"] = "必死即生",
    ["ysch4_shanhedongse"] = "山河动色",
    [":ysch4_shanhedongse"] = "转换技，①若你手牌数为全场最大，“必死即生”改为“转换技”；②若你体力值为全场最小，“必死即生”改为“蓄势技”；③若你手牌数与体力值均为全场唯一，你删除你技能标签。然后你受到一点你的雷电伤害，若满足他项条件，此次将“受到”改为“分配”。",
    ["@ysch4_shanhedongseFrequency"] = "山河动色",
    ["#ysch4_shanhedongse_damage"] = "山河动色：请分配1点雷电伤害！",
    ["LimitedSkill"] = "限定技",
    ["SwitchSkill"] = "转换技",
    ["ReadySkill"] = "蓄势技",
    ["OrdinarySkill"] = "通常技",
    ["@@rfenghou_readying:::ysch4_bisijisheng"] = "必死即生 蓄势中",
}
local fangao = General:new(extension, "ysch4__fangao", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__fangao"] = "梵高",
    ["#ysch4__fangao"] = "苦墨何寻",
    ["designer:ysch4__fangao"] = "一代宗师·三设泰斗·十届轮首·百将皆通·千古绝唱·孤城万里",
    ["cv:ysch4__fangao"] = "未知",
    ["illustrator:ysch4__fangao"] = "未知",
}
local yigerendexingyueye = fk.CreateTriggerSkill{
    name = "ysch4_yigerendexingyueye",
    anim_type = "defensive",
    events = {fk.AfterCardTargetDeclared,fk.StartJudge},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self.name) then
            if event == fk.AfterCardTargetDeclared then
                local cardlist = data.card:isVirtual() and data.card.subcards or {data.card.id}
                return table.contains(TargetGroup:getRealTargets(data.tos), player.id) and #TargetGroup:getRealTargets(data.tos) == 1 and
                (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) and #cardlist > 0
            else
                return #table.filter(player.room.alive_players, function (p)
                    return #p:getCardIds("ej") > 0
                end) > 0 and target == player
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if event == fk.AfterCardTargetDeclared then
            if room:askForSkillInvoke(player,self.name,nil,"#ysch4_yigerendexingyueye-invoke:::"..data.card:toLogString()) then
                return true
            end
        else
            local targets = table.filter(room.alive_players, function (p)
                return #p:getCardIds("ej") > 0
            end)
            local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#ysch4_yigerendexingyueye-target:::"..data.reason, self.name, true, false)
            if #tos > 0 then
                local to = room:getPlayerById(tos[1])
                self.cost_data = room:askForCardChosen(player, to, "ej", self.name, "#ysch4_yigerendexingyueye-card:::"..data.reason)
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.AfterCardTargetDeclared then
            data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
            local cardlist = data.card:isVirtual() and data.card.subcards or {data.card.id}
            for _, id in ipairs(cardlist) do
                if Fk:getCardById(id, true).sub_type == Card.SubtypeDelayedTrick then
                    room:moveCardTo(Fk:getCardById(id, true), Player.Judge, player, fk.ReasonJustMove, self.name)
                else
                    local card = Fk:cloneCard("indulgence")
                    if Fk:getCardById(id, true).color == Card.Black then
                    card = Fk:cloneCard("supply_shortage")
                    end
                    card:addSubcard(id)
                    player:addVirtualEquip(card)
                    room:moveCardTo(card, Player.Judge, player, fk.ReasonJustMove, self.name)  --无视合法性检测
                end
            end
        else
            data.card = Fk:getCardById(self.cost_data)
            data.card.skillName = self.name
            local mark = player:getTableMark("@$ysch4_yigerendexingyueye-phase")
            table.insert(mark,self.cost_data)
            room:setPlayerMark(player,"@$ysch4_yigerendexingyueye-phase",mark)
        end
    end,

    refresh_events = {fk.EventPhaseEnd},
    can_refresh = function (self, event, target, player, data)
        return #player:getTableMark("@$ysch4_yigerendexingyueye-phase") > 0
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local cardlist = player:getTableMark("@$ysch4_yigerendexingyueye-phase")
        for _, id in ipairs(cardlist) do
            if Fk:getCardById(id, true).sub_type == Card.SubtypeDelayedTrick then
                room:moveCardTo(Fk:getCardById(id, true), Player.Judge, player, fk.ReasonJustMove, self.name)
            else
                local card = Fk:cloneCard("indulgence")
                if Fk:getCardById(id, true).color == Card.Black then
                card = Fk:cloneCard("supply_shortage")
                end
                card:addSubcard(id)
                player:addVirtualEquip(card)
                room:moveCardTo(card, Player.Judge, player, fk.ReasonJustMove, self.name)  --无视合法性检测
            end
        end
    end,
}
fangao:addSkill(yigerendexingyueye)
local ranshaodexiangrikui = fk.CreateTriggerSkill{
    name = "ysch4_ranshaodexiangrikui",
    events = {fk.CardEffectFinished},
    anim_type = "drawcard",
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and #TargetGroup:getRealTargets(data.tos) == 1 and not target.dead and player:usedSkillTimes(self.name,Player.HistoryTurn) == 0
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local prompt = "#ysch4_ranshaodexiangrikui-draw::"..target.id
        local num = 1
        while true do
            local use = room:askForNullification(room.alive_players,"nullification","nullification",prompt,true)
            if use then
                num = num + 2
                prompt = "#ysch4_ranshaodexiangrikui-nullification::"..use.from
                room:useCard(use)
            else
                break
            end
        end
        if num%2 == 1 then
            if player:getMark("@@ysch4_ranshaodexiangrikui") ~= 0 then
                local ids = table.random(player:getCardIds{Player.Hand, Player.Equip, Player.Judge},2)
                room:obtainCard(target.id, ids, false, fk.ReasonDraw, target.id, self.name)
            else
                target:drawCards(2,self.name)
            end
        end
    end,

    refresh_events = {fk.AfterTurnEnd},
    can_refresh = function (self, event, target, player, data)
        local room = player.room
        if player:usedSkillTimes(self.name,Player.HistoryTurn) > 0 then
            room:setPlayerMark(player,"@@ysch4_ranshaodexiangrikui",1)
        else
            room:setPlayerMark(player,"@@ysch4_ranshaodexiangrikui",0)
        end
    end,
}
fangao:addSkill(ranshaodexiangrikui)
Fk:loadTranslationTable{
    ["ysch4_yigerendexingyueye"] = "一个人的星月夜",
    [":ysch4_yigerendexingyueye"] = "你可以无效一张目标为你的即时牌，并置入判定区。你判定时，可以改为将场上一张牌作为判定牌，并在阶段结束后将之移入你的判定区。",
    ["#ysch4_yigerendexingyueye-invoke"] = "是否发动 一个人的星月夜，令 %arg 无效并置入判定区",
    ["#ysch4_yigerendexingyueye-target"] = "是否发动 一个人的星月夜，将场上一张牌作为 %arg 的判定牌",
    ["#ysch4_yigerendexingyueye-card"] = "一个人的星月夜：将其中一张牌作为 %arg 的判定牌",
    ["@$ysch4_yigerendexingyueye-phase"] = "一个人的星月夜",
    ["ysch4_ranshaodexiangrikui"] = "燃烧的向日葵",
    [":ysch4_ranshaodexiangrikui"] = "回合技，你可以令一张目标唯一的牌的效果添加【无中生有】。若连续两回合发动，目标获得的牌改为从你的区域内抽取。",
    ["#ysch4_ranshaodexiangrikui-draw"] = "是否使用一张【无懈可击】抵消即将对 %dest 生效的【无中生有】？",
    ["#ysch4_ranshaodexiangrikui-nullification"] = "是否使用一张【无懈可击】抵消 %dest 使用的【无懈可击】？",
    ["@@ysch4_ranshaodexiangrikui"] = "连续发动燃烧的向日葵",
    ["#ysch4_baoyurenshengrugunshizhuiluo-choice"] = "暴雨人生如滚石坠落：是否改为回复所有体力，然后将一个其他技能改为此技能？",
}
for loop = 0, 30, 1 do -- 30个应该够用，没人会获得那么多技能
    local baoyurenshengrugunshizhuiluo = fk.CreateTriggerSkill{
        name = "ysch"..loop.."_baoyurenshengrugunshizhuiluo",
        events = {fk.RoundEnd},
        anim_type = "negative",
        can_trigger = function (self, event, target, player, data)
            return player:hasSkill(self.name) and #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function (e)
                local damage = e.data[5]
                if damage and damage.to == player then
                    return true
                end
            end, Player.HistoryRound) == 0
        end,
        on_cost = function (self, event, target, player, data)
            local room = player.room
            local skills = {}
            for _, skill in ipairs(player.player_skills) do
                if Fk:translate(skill.name,"zh_CN") ~= "暴雨人生如滚石坠落" and skill:isPlayerSkill(player) and not skill.name:startsWith("#") then
                  table.insert(skills, skill.name)
                end
            end
            if #skills > 0 and player:getLostHp() > 0 then
                table.insert(skills,"Cancel")
                self.cost_data = room:askForChoice(player, skills, self.name, "#ysch4_baoyurenshengrugunshizhuiluo-choice", true)
            end
            return true
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            if type(self.cost_data) == "string" and self.cost_data ~= "Cancel" then
                if player:getLostHp() > 0 then
                    room:recover({who = player, num = player:getLostHp(), recoverBy = player, skillName = self.name})
                end
                room:handleAddLoseSkills(player, "-"..self.cost_data, nil, false, false)
                for Skillloop = 0, 30, 1 do
                    local skill = "ysch"..Skillloop.."_baoyurenshengrugunshizhuiluo"
                    if not player:hasSkill(skill) then
                        room:handleAddLoseSkills(player, skill, nil, false, false)
                        break
                    end
                end
            else
                room:loseHp(player, 1, self.name)
            end
        end,
    }
    if loop ~= 4 then
        Fk:addSkill(baoyurenshengrugunshizhuiluo)
    else
        fangao:addSkill(baoyurenshengrugunshizhuiluo)
    end
    Fk:loadTranslationTable{
        ["ysch"..loop.."_baoyurenshengrugunshizhuiluo"] = "暴雨人生如滚石坠落",
        [":ysch"..loop.."_baoyurenshengrugunshizhuiluo"] = "你没有受到伤害的轮次结束时，你须失去一点体力。你在此技能触发时可以改为回复所有体力，然后将一个不为“暴雨人生如滚石坠落”的技能改为此。",
    }
end
local PLJTVJCE = General:new(extension, "ysch4__PLJTVJCE", "god", 4, 4, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__PLJTVJCE"] = "普利特维采",
    ["#ysch4__PLJTVJCE"] = "战争女神",
    ["designer:ysch4__PLJTVJCE"] = "老班长与鱼刺",
    ["cv:ysch4__PLJTVJCE"] = "未知",
    ["illustrator:ysch4__PLJTVJCE"] = "坎特伯雷公主与骑士唤醒冠军之剑的奇幻冒险",
}
local liehuozhanche = fk.CreateTriggerSkill{
    name = "ysch4_liehuozhanche",
    events = {fk.CardUsing},
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and data.card.is_damage_card and player:usedSkillTimes(self.name,Player.HistoryTurn) == 0
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_liehuozhanche_prompt::"..data.from..":"..data.card:toLogString()) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        data.extra_data = data.extra_data or {}
        data.extra_data.ysch4_liehuozhanche = data.extra_data.ysch4_liehuozhanche or {}
        table.insertIfNeed(data.extra_data.ysch4_liehuozhanche,player.id)
        player.room:getPlayerById(data.from):drawCards(1,self.name)
    end,

    refresh_events = {fk.CardUseFinished},
    can_refresh = function (self, event, target, player, data)
        return data.extra_data and data.extra_data.ysch4_liehuozhanche and table.contains(data.extra_data.ysch4_liehuozhanche,player.id) and
        not data.damageDealt and not player.room:getPlayerById(data.from).dead and not player.room:getPlayerById(data.from):isNude()
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local id = room:askForCardChosen(player, room:getPlayerById(data.from), "he", self.name, "#ysch4_liehuozhanche_discard::"..data.from)
        room:throwCard({id}, self.name, room:getPlayerById(data.from), player)
    end,
}
PLJTVJCE:addSkill(liehuozhanche)
local chiyanhuangdao = fk.CreateActiveSkill{
    name = "ysch4_chiyanhuangdao",
    card_filter = Util.TrueFunc,
    target_filter = function(self, to_select, selected, selected_cards, _, _, player)
        if #selected_cards > 0 then
            local card = Fk:cloneCard("iron_chain")
            card:addSubcard(selected_cards[1])
            return card.skill:canUse(player, card) and card.skill:targetFilter(to_select, selected, selected_cards, card, nil, player) and
            not player:prohibitUse(card) and not player:isProhibited(Fk:currentRoom():getPlayerById(to_select), card) and #selected < #selected_cards
        end
    end,
    feasible = function (self, selected, selected_cards, player)
        return #selected > 0 and #selected_cards > 0 and #selected == #selected_cards
    end,
    can_use = function (self, player, card, extra_data)
        return player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryPhase) == 0
    end,
    prompt = "#ysch4_chiyanhuangdao-prompt",
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local redNum = #table.filter(effect.cards,function (id)
            local card = Fk:getCardById(id)
            return card.color == Card.Red
        end)
        room:sortPlayersByAction(effect.tos)
        room:useVirtualCard("iron_chain", effect.cards, player, table.map(effect.tos, Util.Id2PlayerMapper), self.name)

        if redNum > 0 then
            local tos = room:askForChoosePlayers(player,effect.tos,1,1,"#ysch4_chiyanhuangdao-fire:::"..redNum,self.name,false)
            if #tos > 0 then
                local card = Fk:cloneCard("fire_attack")
                local use = {
                    from = player.id,
                    tos = table.map(tos, function(id) return { id } end),
                    card = card,
                    extraUse = true,
                    additionalEffect = redNum - 1
                }
                room:useCard(use)
            end
        end
    end,
}
PLJTVJCE:addSkill(chiyanhuangdao)
Fk:loadTranslationTable{
    ["ysch4_liehuozhanche"] = "烈火战车",
    [":ysch4_liehuozhanche"] = "回合技，一名角色使用伤害牌时，你可以令其摸一张牌，然后若之未造成伤害，你弃置其一张牌。",
    ["#ysch4_liehuozhanche_prompt"] = "是否发动 烈火战车，令%dest摸一张牌，若%arg未造成伤害，你弃置其一张牌",
    ["#ysch4_liehuozhanche_discard"] = "烈火战车：弃置%dest一张牌",
    ["ysch4_chiyanhuangdao"] = "赤焰凰蹈",
    [":ysch4_chiyanhuangdao"] = "阶段技，你可以将任意张牌当做等目标的【铁锁连环】使用，然后视为对其中一名角色使用结算其中红色牌数次的【火攻】。",
    ["#ysch4_chiyanhuangdao-prompt"] = "赤焰凰蹈：你可以将任意张牌当做等目标的【铁锁连环】使用",
    ["#ysch4_chiyanhuangdao-fire"] = "赤焰凰蹈：视为对其中一名角色使用结算 %arg 次的【火攻】",
}
local weigongqiesi = General:new(extension, "ysch4__weigongqiesi", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__weigongqiesi"] = "卫宫切嗣",
    ["#ysch4__weigongqiesi"] = "敌法师",
    ["designer:ysch4__weigongqiesi"] = "志文",
    ["cv:ysch4__weigongqiesi"] = "未知",
    ["illustrator:ysch4__weigongqiesi"] = "Fate",
}
local qiyuandan = fk.CreateViewAsSkill{
    name = "ysch4_qiyuandan",
    pattern = "slash",
    anim_type = "offensive",
    interaction = function()
        local all_choices = {"WeaponSlot", "ArmorSlot", "DefensiveRideSlot", "OffensiveRideSlot", "TreasureSlot"}
        local subtypes = {Card.SubtypeWeapon, Card.SubtypeArmor, Card.SubtypeDefensiveRide, Card.SubtypeOffensiveRide, Card.SubtypeTreasure}
        local choices = {}
        for i = 1, 5, 1 do
            if #Self:getAvailableEquipSlots(subtypes[i]) > 0 then
                table.insert(choices, all_choices[i])
            end
        end
        if #choices > 0 then
            return U.CardNameBox { choices = choices, all_choices = all_choices }
        end
    end,
    card_filter = Util.FalseFunc,
    view_as = function (self, cards, player)
        if not self.interaction.data then return end
        local card = Fk:cloneCard("slash")
        card.skillName = self.name
        return card
    end,
    before_use = function(self, player, use)
        local room = player.room
        room:abortPlayerArea(player, {self.interaction.data})
    end,
}
local qiyuandan_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_qiyuandan_trigger",
    refresh_events = {fk.DamageCaused},
    can_refresh = function (self, event, target, player, data)
        return data.card and data.card.skillName == "ysch4_qiyuandan" and target == player
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local skills = {}
        local to = data.to
        for _, skill in ipairs(to.player_skills) do
            if skill:isPlayerSkill(to) and not skill.name:startsWith("#") then
                  table.insert(skills, skill.name)
            end
        end
        table.insert(skills,"Cancel")
        local choice = "Cancel"
        if #skills > 1 then
            choice = room:askForChoice(to, skills, self.name, "#ysch4_qiyuandan-choice:::"..(#skills-1), true)
        end
        if choice == "Cancel" then
            data.damage = data.damage + #skills - 1
        else
            room:handleAddLoseSkills(to, "-"..choice)
        end
    end,
}
qiyuandan:addRelatedSkill(qiyuandan_trigger)
weigongqiesi:addSkill(qiyuandan)
Fk:addQmlMark{
    name = "color",
    how_to_show = function(_, value)
        if type(value) ~= "table" then return " " end
        return table.concat(table.map(value, function(color)
            if color == Card.Red then
                return "<font color='red'>红</font>"
            else
                return "黑"
            end
        end), " ")
    end,
    qml_path = "",
}
local guyoushiyu = fk.CreateTriggerSkill{
    name = "ysch4_guyoushiyu",
    events = {fk.AfterCardsMove},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self.name) then
            return data.ysch4_guyoushiyu
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local prompt = "#ysch4_guyoushiyu-invoke"
        local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
        if turn_event then
            local to = turn_event.data[1]
            if to.id == player.id then
                prompt = "#ysch4_guyoushiyu-prompt"
            end
        end
        if room:askForSkillInvoke(player,self.name,nil,prompt) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local turn_event = room.logic:getCurrentEvent():findParent(GameEvent.Turn)
        if turn_event then
            local to = turn_event.data[1]
            if to.id == player.id then
                room:setPlayerMark(player,"@@ysch4_guyoushiyu",1)
            end
        end
        room:endTurn()
    end,

    refresh_events = {fk.AfterCardsMove,fk.TurnStart,fk.PreDamage},
    can_refresh = function(self, event, target, player, data)
        if event == fk.AfterCardsMove then
            if player:hasSkill(self.name) then
                for _, move in ipairs(data) do
                    if move.toArea == Card.DiscardPile then
                        return true
                    end
                end
            end
        elseif event == fk.TurnStart then
            return target == player and player:getMark("@@ysch4_guyoushiyu") ~= 0
        else
            return data.card and data.card.color == Card.Black and player:getMark("@@ysch4_guyoushiyu") ~= 0
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.AfterCardsMove then
            local mark = player:getTableMark("@[color]ysch4_guyoushiyu")
            local color, trueColor = {}, {}
            for _, move in ipairs(data) do
                if move.toArea == Card.DiscardPile then
                    for _, info in ipairs(move.moveInfo) do
                        if Fk:getCardById(info.cardId).color ~= Card.NoColor then
                            table.insert(color,Fk:getCardById(info.cardId).color)
                            table.insertIfNeed(trueColor,Fk:getCardById(info.cardId).color)
                        end
                    end
                end
            end
            if #color > #trueColor then
                data.ysch4_guyoushiyu = true
            end
            if #mark > 0 then
                for _, value in ipairs(mark) do
                    if table.contains(trueColor,value) then
                        data.ysch4_guyoushiyu = true
                        break
                    end
                end
            end
            room:setPlayerMark(player,"@[color]ysch4_guyoushiyu",trueColor)
        elseif event == fk.TurnStart then
            room:setPlayerMark(player,"@@ysch4_guyoushiyu",0)
        else
            data.from = player
        end
    end,
    on_lose = function (self, player, is_death)
        player.room:setPlayerMark(player,"@[color]ysch4_guyoushiyu",0)
    end,
}
weigongqiesi:addSkill(guyoushiyu)
Fk:loadTranslationTable{
    ["ysch4_qiyuandan"] = "起源弹",
    [":ysch4_qiyuandan"] = "你可废除一个装备栏，视为使用【杀】。受到此【杀】伤害的角色选择一项：1.此伤害+X（X为其的技能数）；2.失去一项技能。",
    ["#ysch4_qiyuandan_trigger"] = "起源弹",
    ["#ysch4_qiyuandan-choice"] = "起源弹：失去一个技能，或令此伤害+%arg",
    ["ysch4_guyoushiyu"] = "固有时域",
    [":ysch4_guyoushiyu"] = "连续两张同颜色的牌进入弃牌堆后，你可终止这个回合；若为你的回合，在你的下回合开始前，你视为所有黑色牌的伤害来源。",
    ["@@ysch4_guyoushiyu"] = "黑牌的伤害来源",
    ["@[color]ysch4_guyoushiyu"] = "固有时域",
    ["#ysch4_guyoushiyu-invoke"] = "是否发动 固有时域，结束此回合",
    ["#ysch4_guyoushiyu-prompt"] = "是否发动 固有时域，结束此回合，然后直至你下回合开始前，你视为所有黑色牌的伤害来源",
}
local chenglong = General:new(extension, "ysch4__chenglong", "han", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__chenglong"] = "成龙",
    ["#ysch4__chenglong"] = "",
    ["designer:ysch4__chenglong"] = "铝&独孤妙妙",
    ["cv:ysch4__chenglong"] = "赵岭",
    ["illustrator:ysch4__chenglong"] = "龍之寶工作室",
}
local busitushou = fk.CreateFilterSkill{
    name = "ysch4_busitushou",
    handly_cards = function (self, player)
        if player:isKongcheng() then
            return player:getTableMark("ysch4_busitushou-turn")
        end
    end,
}
local busitushou_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_busitushou_trigger",
    mute = true,
    refresh_events = {fk.PreCardUse,fk.AskForCardUse, fk.AskForCardResponse,fk.AfterCardsMove,fk.AfterDrawPileShuffle},
    can_refresh = function(self, event, target, player, data)
        if player:hasSkill(busitushou) then
            if event == fk.PreCardUse then
                return target == player and #table.filter(Card:getIdList(data.card),function (id)
                    return table.contains(player:getTableMark("ysch4_busitushou-turn"),id)
                end) > 0
            else
                return true
            end
        end
    end,
    on_refresh = function(self, event, target, player, data)
        local room = player.room
        if event == fk.PreCardUse then
            room:notifySkillInvoked(player,"ysch4_busitushou","special")
            player:broadcastSkillInvoke("ysch4_busitushou")
        end
        local n = math.min(#(room:getBanner("@$CenterArea") or Util.DummyTable),8)
        local ids = {}
        for i = 1, n, 1 do
            if i > #room.draw_pile then break end
            table.insert(ids, room.draw_pile[i])
        end
        player.room:setPlayerMark(player, "ysch4_busitushou-turn", ids)
    end,
}
busitushou.CenterArea = true
busitushou:addRelatedSkill(busitushou_trigger)
chenglong:addSkill(busitushou)
--- 变更战场
--- @param room Room @ 游戏房间
--- @param from? ServerPlayer @ 发起角色
--- @param tos ServerPlayer | ServerPlayer[] @ 进入或离开战场的角色（列表）
--- @param battle string @ 进入或离开的战场
--- @param skillName? string @ 技能名
local ChangeBattlefield = function (room,from,tos,battle,skillName)
    local Enter, Leave, Change = {}, {}, {}
    if tos.class then tos = { tos } end
    for _, cp in ipairs(tos) do
        if cp:getMark("@[:]Battlefield") ~= battle then
            if cp:getMark("@[:]Battlefield") ~= 0 then
                table.insert(Change,{cp.id,cp:getMark("@[:]Battlefield")})
            end
            table.insert(Enter,cp.id)
            room:setPlayerMark(cp,"@[:]Battlefield",battle)
        else
            table.insert(Leave,cp.id)
            room:setPlayerMark(cp,"@[:]Battlefield",0)
        end
    end
    if from then
        if #Enter > 0 then
            room:sendLog{type = "#EnterJiajuchengFrom-log",from = from.id,to = Enter,arg = battle,toast = true}
        end
        if #Leave > 0 then
            room:sendLog{type = "#LeaveJiajuchengFrom-log",from = from.id,to = Leave,arg = battle,toast = true,}
        end
    else
        if #Enter > 0 then
            room:sendLog{type = "#EnterJiajucheng-log",to = Enter,arg = battle,toast = true,}
        end
        if #Leave > 0 then
            room:sendLog{type = "#LeaveJiajucheng-log",to = Leave,arg = battle,toast = true,}
        end
    end
    for _, id in ipairs(Enter) do
        local player = room:getPlayerById(id)
        room.logic:trigger("fk.EnterBattlefield", player, {battle = battle,from = from,skillName = skillName})
    end
    for _, value in ipairs(Change) do
        local player = room:getPlayerById(value[1])
        local leaveBattle = value[2]
        room.logic:trigger("fk.LeaveBattlefield", player, {battle = leaveBattle,from = from,skillName = skillName})
    end
    for _, id in ipairs(Leave) do
        local player = room:getPlayerById(id)
        room.logic:trigger("fk.LeaveBattlefield", player, {battle = battle,from = from,skillName = skillName})
    end
end
local lingyuzhankai = fk.CreateViewAsSkill{
    name = "ysch4_lingyuzhankai",
    pattern = ".",
    prompt = function (self)
        return "#ysch4_lingyuzhankai-invoke::"..Self:getMark("ysch4_lingyuzhankai")
    end,
    card_filter = Util.FalseFunc,
    view_as = function (self, cards, player)
        local names, all_names = {} , {}
        for _, id in ipairs(Fk:getAllCardIds()) do
            local card = Fk:getCardById(id)
            if (card.type == Card.TypeBasic or card.type == Card.TypeTrick) and not card.is_derived and not table.contains(all_names, card.name) then
                table.insert(all_names, card.name)
                local to_use = Fk:cloneCard(card.name)
                if ((Fk.currentResponsePattern == nil and Self:canUse(to_use) and not Self:prohibitUse(to_use)) or
                (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(to_use))) then
                    table.insert(names, card.name)
                end
            end
        end
        if #names == 0 then return false end
        local card = Fk:cloneCard(names[#names])
        card.skillName = self.name
        return card
    end,
    before_use = function (self, player, use)
        local room = player.room
        local last = room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
            return true
        end, 1)[1]
        if last and last.data[1].from ~= player.id then
            local to = room:getPlayerById(last.data[1].from)
            ChangeBattlefield(room,nil,{player,to},"ysch4_jiajuncheng",self.name)
        end
        room:setPlayerMark(player,"ysch4_lingyuzhankai",0)
        return ""
    end,
    enabled_at_play = function (self, player)
        return player:getMark("ysch4_lingyuzhankai") ~= 0
    end,
    enabled_at_response = function (self, player, response)
        return not response and player:getMark("ysch4_lingyuzhankai") ~= 0
    end,
}
local lingyuzhankai_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_lingyuzhankai_trigger",

    refresh_events = {fk.CardUsing,fk.CardUseFinished,fk.AfterAskForCardUse,fk.AfterCardsMove,fk.AskForCardUse},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(lingyuzhankai.name)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local last = room.logic:getEventsByRule(GameEvent.UseCard, 1, function (e)
            return true
        end, 1)[1]
        if last and last.data[1].from ~= player.id then
            room:setPlayerMark(player,"ysch4_lingyuzhankai",last.data[1].from)
        else
            room:setPlayerMark(player,"ysch4_lingyuzhankai",0)
        end
    end,
}
lingyuzhankai:addRelatedSkill(lingyuzhankai_trigger)
chenglong:addSkill(lingyuzhankai)
local jiajucheng = fk.CreateTriggerSkill{
    name = "#ysch4_jiajuncheng",
    global = true,
    refresh_events = {fk.BeforeCardsMove,"fk.EnterBattlefield","fk.LeaveBattlefield"},
    can_refresh = function (self, event, target, player, data)
        if event == fk.BeforeCardsMove then
            for _, move in ipairs(data) do
                if move.to == player.id and move.toArea == Card.PlayerHand and player:getMark("@[:]Battlefield") == "ysch4_jiajuncheng" then
                    return true
                end
            end
        else
            return target == player and data.battle == "ysch4_jiajuncheng"
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.BeforeCardsMove then
            local ids = {}
            local mirror_moves = {}
            for index, move in ipairs(data) do
                if move.to == player.id and move.toArea == Card.PlayerHand then
                    local mirror_info = {}
                    for _, info in ipairs(move.moveInfo) do
                        table.insertIfNeed(ids,info.cardId)
                        table.insert(mirror_info, table.simpleClone(info))
                        move.moveInfo = {}
                    end
                    if #mirror_info > 0 then
                        local new_move = table.simpleClone(move)
                        new_move.to = nil
                        new_move.toArea = Card.DiscardPile
                        new_move.moveReason = fk.ReasonPutIntoDiscardPile
                        new_move.moveInfo = mirror_info
                        new_move.moveMark = nil
                        new_move.moveVisible = true
                        table.insert(mirror_moves, new_move)
                    end
                end
            end
            room:notifySkillInvoked(player,self.name,"negative")
            room:sendLog({
                type = "#ysch4_jiajuncheng-log",
                from = player.id,
                toast = true,
            })
            if #mirror_moves > 0 then
                data = mirror_moves
                room:moveCards({ids = ids,toArea = Card.DiscardPile,moveReason = fk.ReasonPutIntoDiscardPile,moveMark = nil,moveVisible = true})
            end
        elseif event == "fk.EnterBattlefield" then
            room:handleAddLoseSkills(player, "ysch4_longhun&", nil, false, true)
        else
            room:handleAddLoseSkills(player, "-ysch4_longhun&", nil, false, true)
        end
    end,
}
Fk:addSkill(jiajucheng)
local longhun = fk.CreateViewAsSkill{
    name = "ysch4_longhun&",
    pattern = "peach,slash,jink,nullification",
    handly_pile = true,
    card_filter = function(self, to_select, selected, player)
        if #selected == 2 then
            return false
        elseif #selected == 1 then
            return Fk:getCardById(to_select):compareSuitWith(Fk:getCardById(selected[1]))
        else
            local suit = Fk:getCardById(to_select).suit
            local c
            if suit == Card.Heart then
            c = Fk:cloneCard("peach")
            elseif suit == Card.Diamond then
            c = Fk:cloneCard("fire__slash")
            elseif suit == Card.Club then
            c = Fk:cloneCard("jink")
            elseif suit == Card.Spade then
            c = Fk:cloneCard("nullification")
            else
            return false
            end
            return (Fk.currentResponsePattern == nil and c.skill:canUse(player, c)) or (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(c))
        end
    end,
    view_as = function(self, cards)
        if #cards == 0 or #cards > 2 then
            return nil
        end
        local suit = Fk:getCardById(cards[1]).suit
        local c
        if suit == Card.Heart then
            c = Fk:cloneCard("peach")
        elseif suit == Card.Diamond then
            c = Fk:cloneCard("fire__slash")
        elseif suit == Card.Club then
            c = Fk:cloneCard("jink")
        elseif suit == Card.Spade then
            c = Fk:cloneCard("nullification")
        else
            return nil
        end
        c.skillName = self.name
        c:addSubcards(cards)
        return c
    end,
    before_use = function(self, player, use)
        local num = #use.card.subcards
        if num == 2 then
            local suit = Fk:getCardById(use.card.subcards[1]).suit
            if suit == Card.Diamond then
            use.additionalDamage = (use.additionalDamage or 0) + 1
            elseif suit == Card.Heart then
            use.additionalRecover = (use.additionalRecover or 0) + 1
            end
        end
    end,
    can_use = function()
        return Self:getMark("@[:]Battlefield") == "ysch4_jiajuncheng"
    end,
    enabled_at_play = function (self, player)
        return player:getMark("@[:]Battlefield") == "ysch4_jiajuncheng"
    end,
    enabled_at_response = function (self, player, response)
        return player:getMark("@[:]Battlefield") == "ysch4_jiajuncheng"
    end,
}
local longhun_discard = fk.CreateTriggerSkill{
    name = "#ysch4_longhun_discard",
    events = {fk.CardUseFinished},
    mute = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and table.contains(data.card.skillNames, "ysch4_longhun&") and #data.card.subcards == 2 and Fk:getCardById(data.card.subcards[1]).color == Card.Black
    end,
    on_cost = function() return true end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if not room.current:isNude() then
            local cid = room:askForCardChosen(player, room.current, "he", self.name)
            room:throwCard({cid}, self.name, room.current, player)
        end
    end,
}
longhun:addRelatedSkill(longhun_discard)
Fk:addSkill(longhun)
Fk:loadTranslationTable{
    ["ysch4_busitushou"] = "不死徒手",
    [":ysch4_busitushou"] = "若你没有手牌，你可以如手牌般使用或打出牌堆顶的X张牌。（X为中央区牌数，至多为八）",
    ["#ysch4_busitushou_filter"] = "不死徒手",
    ["ysch4_lingyuzhankai"] = "领域展开",
    [":ysch4_lingyuzhankai"] = "<a href = ':Battlefield'>战场技！</a>连招技（其他角色使用牌+你需要使用牌），你可以与前者进入或离开<a href = ':ysch4_jiajuncheng'>〖家具城〗</a>。",
    ["#ysch4_lingyuzhankai-invoke"] = "是否发动 领域展开，与 %dest 进入或离开〖家具城〗",
    ["@[:]Battlefield"] = "战场",
    [":Battlefield"] = "<b>战场技！</b>——<br>可以令角色进入或离开特定战场的技能，位于战场的角色须执行战场规则，战场不会因战场技！持有者死亡或技能失效而消失，但会被其他战场顶替。"..
    "<br>特别的，特殊战场之间可以共存，例如海洋和岛屿，街道和家具城",
    ["ysch4_jiajuncheng"] = "家具城",
    ["#ysch4_jiajuncheng"] = "家具城",
    [":ysch4_jiajuncheng"] = "在此区域内的角色可以发动“<a href = ':ysch4_longhun&'>龙魂</a>”，但获得牌时改为置入弃牌堆。",
    ["#ysch4_jiajuncheng-log"] = "%from 获得的牌改为置入弃牌堆",
    ["#EnterJiajucheng-log"] = "%to 进入了 〖%arg〗",
    ["#LeaveJiajucheng-log"] = "%to 离开了 〖%arg〗",
    ["#EnterJiajuchengFrom-log"] = "%from 令 %to 进入了 〖%arg〗",
    ["#LeaveJiajuchengFrom-log"] = "%from 令 %to 离开了 〖%arg〗",
    ["ysch4_longhun&"] = "龙魂",
    [":ysch4_longhun&"] = "你可以将至多两张你的同花色的牌按以下规则使用或打出：红桃当【桃】，方块当火【杀】，梅花当【闪】，黑桃当【无懈可击】。若你以此法使用或打出了两张：红桃牌，此牌回复基数+1；方块牌，此牌伤害基数+1；黑色牌，你弃置当前回合角色一张牌。",
    ["#ysch4_longhun_discard"] = "龙魂",

    ["$ysch4_busitushou1"] = "飞身踢xN",
    ["$ysch4_busitushou2"] = "（打斗声）",
    ["$ysch4_lingyuzhankai1"] = "对不起对不起，先借用一下。",
    ["$ysch4_lingyuzhankai2"] = "我怎么感觉自己好像来过这里，这到底是为什么。",
    ["~ysch4__chenglong"] = "倒霉xN",
}
local simayi = General:new(extension, "ysch4__simayi", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__simayi"] = "司马懿",
    ["#ysch4__simayi"] = "掌日凌穹",
    ["designer:ysch4__simayi"] = "云雀",
    ["cv:ysch4__simayi"] = "佚名",
    ["illustrator:ysch4__simayi"] = "米糊PU",
}
local qianlang = fk.CreateTriggerSkill{
    name = "ysch4_qianlang",
    frequency = Skill.Limited,
    anim_type = "big",
    events = {fk.BeforeHpChanged,fk.BeforeCardsMove},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0 then
            if event == fk.BeforeHpChanged then
                return target == player and player.hp == 0 and #table.filter(player.room:getOtherPlayers(player), function(p)
                    return p.hp > player.hp
                end) > 0
            elseif event == fk.BeforeCardsMove then
                if player:getHandcardNum() == 0 then
                    for _, move in ipairs(data) do
                        if move.to == player.id and move.toArea == Card.PlayerHand and #table.filter(player.room:getOtherPlayers(player), function(p)
                            return #p:getCardIds(Player.Hand) > #player:getCardIds(Player.Hand)
                        end) > 0 then
                            return true
                        end
                        if move.from == player.id then
                            for _, info in ipairs(move.moveInfo) do
                                if info.fromArea == Card.PlayerHand and #table.filter(player.room:getOtherPlayers(player), function(p)
                                    return #p:getCardIds(Player.Hand) > #player:getCardIds(Player.Hand)
                                end) > 0 then
                                    return true
                                end
                            end
                        end
                    end
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local prompt = "#ysch4_qianlang-card"
        if event == fk.BeforeHpChanged then
            prompt = "#ysch4_qianlang-hp"
        end
        if player.room:askForSkillInvoke(player,self.name,nil,prompt) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.BeforeHpChanged then
            if #table.filter(room:getOtherPlayers(player), function(p)
                return p.hp > player.hp
            end) then
                local hp = 0
                for _, p in ipairs(room:getOtherPlayers(player)) do
                    hp = math.max(hp, p.hp)
                end
                if player:isWounded() and not player.dead then
                    room:recover{
                        who = player,
                        num = hp - player.hp,
                        recoverBy = player,
                        skillName = self.name,
                    }
                end
            end
        else
            if #table.filter(room:getOtherPlayers(player), function(p)
                return #p:getCardIds(Player.Hand) > #player:getCardIds(Player.Hand)
            end) then
                local draw = 0
                for _, p in ipairs(room:getOtherPlayers(player)) do
                    draw = math.max(draw, p:getHandcardNum())
                end
                player:drawCards(draw - player:getHandcardNum(), self.name)
            end
        end
    end,
}
simayi:addSkill(qianlang)
local sidai = fk.CreateTriggerSkill{
    name = "ysch4_sidai",
    anim_type = "control",
    events = {fk.CardRespondFinished , fk.CardUseFinished},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
            if data.responseToEvent and data.responseToEvent.from and 
            (data.responseToEvent.card.type == Card.TypeBasic or data.responseToEvent.card:isCommonTrick()) then
                if target == player then
                    local from = player.room:getPlayerById(data.responseToEvent.from)
                    if from and from:isAlive() and from ~= player then
                        self.cost_data = from.id
                        return true
                    end
                else
                    local from = player.room:getPlayerById(data.responseToEvent.from)
                    if from and from:isAlive() and from == player then
                        self.cost_data = target.id
                        return true
                    end
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_sidai-invoke::"..self.cost_data) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data)
        U.swapHandCards(room, player, player, to, self.name)
    end,
}
simayi:addSkill(sidai)
local hudao = fk.CreateTriggerSkill{
    name = "ysch4_hudao",
    anim_type = "switch",
    switch_skill_name = "ysch4_hudao",
    events = {fk.Damage,fk.Damaged},
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(self)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local choices = {}
        local prompt = "#ysch4_hudao-yang"
        if player:getSwitchSkillState(self.name) == fk.SwitchYang then
            choices = {"@@ysch4_hudao1Black1","@@ysch4_hudao1Black2","@@ysch4_hudao1Red1","@@ysch4_hudao1Red2"}
        else
            prompt = "#ysch4_hudao-yin"
            choices = {"@@ysch4_hudao2Black1","@@ysch4_hudao2Black2","@@ysch4_hudao2Red1","@@ysch4_hudao2Red2"}
        end
        if #choices > 0 then
            table.insert(choices,"Cancel")
            local choice = room:askForChoice(player,choices,self.name,prompt)
            if choice ~= "Cancel" then
                self.cost_data = choice
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:setPlayerMark(player,self.cost_data,1)
    end,

    refresh_events = {fk.CardUsing},
    can_refresh = function (self, event, target, player, data)
        local mark = {{{"@@ysch4_hudao1Black1","@@ysch4_hudao1Black2"},{"@@ysch4_hudao1Red1","@@ysch4_hudao1Red2"}},
        {{"@@ysch4_hudao2Black1","@@ysch4_hudao2Black2"},{"@@ysch4_hudao2Red1","@@ysch4_hudao2Red2"}}}
        if data.tos and table.contains(TargetGroup:getRealTargets(data.tos), player.id) then
            if data.card.color == Card.Black then
                return player:getMark(mark[1][1][1]) ~= 0 or player:getMark(mark[1][1][2])
            elseif data.card.color == Card.Red then
                return player:getMark(mark[1][2][1]) ~= 0 or player:getMark(mark[1][2][2])
            end
        elseif target == player then
            if data.card.color == Card.Black then
                return player:getMark(mark[2][1][1]) ~= 0 or player:getMark(mark[2][1][2])
            elseif data.card.color == Card.Red then
                return player:getMark(mark[2][2][1]) ~= 0 or player:getMark(mark[2][2][2])
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark = {{{"@@ysch4_hudao1Black1","@@ysch4_hudao1Black2"},{"@@ysch4_hudao1Red1","@@ysch4_hudao1Red2"}},
        {{"@@ysch4_hudao2Black1","@@ysch4_hudao2Black2"},{"@@ysch4_hudao2Red1","@@ysch4_hudao2Red2"}}}
        if data.tos and table.contains(TargetGroup:getRealTargets(data.tos), player.id) then
            if data.card.color == Card.Black then
                if player:getMark(mark[1][1][1]) ~= 0 then
                    data.additionalEffect = (data.additionalEffect or 0) + 1
                    room:setPlayerMark(player,mark[1][1][1],0)
                end
                if player:getMark(mark[1][1][2]) ~= 0 then
                    data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
                    room:setPlayerMark(player,mark[1][1][2],0)
                end
            elseif data.card.color == Card.Red then
                if player:getMark(mark[1][2][1]) ~= 0 then
                    data.additionalEffect = (data.additionalEffect or 0) + 1
                    room:setPlayerMark(player,mark[1][2][1],0)
                end
                if player:getMark(mark[1][2][2]) ~= 0 then
                    data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
                    room:setPlayerMark(player,mark[1][2][2],0)
                end
            end
        elseif target == player then
            if data.card.color == Card.Black then
                if player:getMark(mark[2][1][1]) ~= 0 then
                    data.additionalEffect = (data.additionalEffect or 0) + 1
                    room:setPlayerMark(player,mark[2][1][1],0)
                end
                if player:getMark(mark[2][1][2]) ~= 0 then
                    data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
                    room:setPlayerMark(player,mark[2][1][2],0)
                end
            elseif data.card.color == Card.Red then
                if player:getMark(mark[2][2][1]) ~= 0 then
                    data.additionalEffect = (data.additionalEffect or 0) + 1
                    room:setPlayerMark(player,mark[2][2][1],0)
                end
                if player:getMark(mark[2][2][2]) ~= 0 then
                    data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
                    room:setPlayerMark(player,mark[2][2][2],0)
                end
            end
        end
    end,
}
simayi:addSkill(hudao)
Fk:loadTranslationTable{
    ["ysch4_qianlang"] = "潜狼",
    [":ysch4_qianlang"] = "限定技，当你的体力或手牌从零开始变化时，你可以将之调整至场上最大。",
    ["#ysch4_qianlang-hp"] = "是否发动 潜狼，将体力调整至场上最大",
    ["#ysch4_qianlang-card"] = "是否发动 潜狼，将手牌调整至场上最多",
    ["ysch4_sidai"] = "伺待",
    [":ysch4_sidai"] = "当你与其他角色的响应对方的即时牌时，你可以与其交换手牌。",
    ["#ysch4_sidai-invoke"] = "是否发动 伺待，与 %dest 交换手牌",
    ["ysch4_hudao"] = "狐蹈",
    [":ysch4_hudao"] = "转换技，当你造成或受到伤害后，你可以令①以你为目标②你使用的下一张黑色或红色牌结算两次或无效。",
    ["#ysch4_hudao-yang"] = "是否发动 狐蹈，令以你为目标的下一张黑色或红色牌结算两次或无效",
    ["#ysch4_hudao-yin"] = "是否发动 狐蹈，令你使用的下一张黑色或红色牌结算两次或无效",
    ["@@ysch4_hudao1Black1"] = "黑牌对你多结",
    ["@@ysch4_hudao1Black2"] = "黑牌对你无效",
    ["@@ysch4_hudao1Red1"] = "<font color='red'>红牌</font>对你多结",
    ["@@ysch4_hudao1Red2"] = "<font color='red'>红牌</font>对你无效",
    ["@@ysch4_hudao2Black1"] = "你用黑牌多结",
    ["@@ysch4_hudao2Black2"] = "你用黑牌无效",
    ["@@ysch4_hudao2Red1"] = "你用<font color='red'>红牌</font>多结",
    ["@@ysch4_hudao2Red2"] = "你用<font color='red'>红牌</font>无效",

    ["$ysch4_qianlang1"] = "俯首谢罪、告病守成，岂是屈膝事孺子？",
    ["$ysch4_qianlang2"] = "天地不昭昭、王德不尧尧。",
    ["$ysch4_sidai1"] = "余生自负澄清志，静坐草庐待春雷。",
    ["$ysch4_sidai2"] = "青芝不发，白霜未晞；潜鳞戢志，伺震而飞！",
    ["$ysch4_hudao1"] = "孤三进三止，宁不知九鼎轻重邪？",
    ["$ysch4_hudao2"] = "孙刘何负？衣带一江、翠屏一山耳。",
    ["~ysch4__simayi"] = "几人真得鹿？终日梦为鱼。",
}
local yangzhiyangyan = General:new(extension, "ysch4__yangzhiyangyan", "jin", 4, 4, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__yangzhiyangyan"] = "杨芷杨艳",
    ["#ysch4__yangzhiyangyan"] = "妍芷艳质",
    ["designer:ysch4__yangzhiyangyan"] = "静谦",
    ["cv:ysch4__yangzhiyangyan"] = "佚名",
    ["illustrator:ysch4__yangzhiyangyan"] = "张艺骞",
}
local yinfu_bogusFlowerSkill = fk.CreateActiveSkill{
    name = "#yinfu_ysch_Al__bogus_flower_skill",
    mute = true,
    mod_target_filter = Util.TrueFunc,
    on_use = function(self, room, cardUseEvent)
        if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
            cardUseEvent.tos = { { cardUseEvent.from } }
        end
    end,
    on_effect = function(self, room, effect)
        local target = room:getPlayerById(effect.to)
        if target.dead or target:isNude() then return end
        local cards = room:askForDiscard(target, 1, 2, true, "ysch_Al__bogus_flower", false, ".", "#ysch_Al__bogus_flower-discard", true)
        if #cards == 0 then return end
        local n = #cards
        if table.find(cards, function(id) return Fk:getCardById(id).type == Card.TypeEquip end) then
            n = n + 1
        end
        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if use_event then
            local use = use_event.data[1]
            use.extra_data = use.extra_data or {}
            use.extra_data.ysch4_yinfu = use.extra_data.ysch4_yinfu or {}
            table.insertTableIfNeed(use.extra_data.ysch4_yinfu, cards)
        end
        room:throwCard(cards, "ysch_Al__bogus_flower", target, target)
        if not target.dead then
            target:drawCards(n, "ysch_Al__bogus_flower")
        end
    end
}
Fk:addSkill(yinfu_bogusFlowerSkill)
Fk:addQmlMark{
    name = "maihuo",
    how_to_show = function(_, value)
        if type(value) ~= "table" then return " " end
        local player = Fk:currentRoom():getPlayerById(value[#value])
        if (not player) or (not player.general) or (player.general == "") then return " " end
        local ret = player.general
        if player.deputyGeneral and player.deputyGeneral ~= "" then
            ret = "seat#" .. player.seat
        end
        return Fk:translate(ret)
    end,
    qml_path = function(name, value, p)
        if Self:isBuddy(p) or not string.startsWith(name, "@[maihuo]$") then
            return "packages/utility/qml/PlayerBox"
        end
        return ""
    end,
}
local yinfu = fk.CreateTriggerSkill{
    name = "ysch4_yinfu",
    events = {fk.TurnEnd},
    anim_type = "drawcard",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            local mark = player:getTableMark("#ysch4_yinfu_mark")
            if #mark == 3 then
                if player.hp > mark[1] then
                    return true
                end
                if player:getHandcardNum() > mark[2] then
                    return true
                end
                if #player.player_cards[Player.Equip] > mark[3] then
                    return true
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local to = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1, "#ysch4_yinfu-invoke", self.name, true)
        if #to > 0 then
            self.cost_data = {tos = to}
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark("@[maihuo]ysch4_yinfu")
        local to = room:getPlayerById(self.cost_data.tos[1])
        if not to.dead then
            local use = room:useVirtualCard("ysch_Al__bogus_flower", nil, to, to, self.name)
            if use and use.extra_data and use.extra_data.ysch4_yinfu then
                if table.contains(mark,self.cost_data.tos[1]) then
                    table.removeOne(mark,self.cost_data.tos[1])
                end
                table.insertIfNeed(mark,self.cost_data.tos[1])
                local targets = table.filter(room:getOtherPlayers(to),function (cp)
                    return cp:usedCardTimes("ysch_Al__bogus_flower",Player.HistoryGame) > 0
                end)
                if #targets > 0 then
                    local cards = use.extra_data.ysch4_yinfu
                    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#ysch4_yinfu-gain", self.name, true)
                    if #tos > 0 then
                        if table.contains(mark,tos[1]) then
                            table.removeOne(mark,tos[1])
                        end
                        table.insertIfNeed(mark,tos[1])
                        room:obtainCard(tos[1],cards,true,fk.ReasonJustMove,player.id,self.name)
                    end
                end
            end
        end
        room:setPlayerMark(player,"@[maihuo]ysch4_yinfu",mark)
    end,

    refresh_events = {fk.PreCardEffect},
    can_refresh = function (self, event, target, player, data)
        if data.card.trueName == "bogus_flower" then
            return data.card.skillName == self.name
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local card = data.card:clone()
        local c = table.simpleClone(data.card)
        for k, v in pairs(c) do
            card[k] = v
        end
        card.skill = yinfu_bogusFlowerSkill
        data.card = card
    end,
}
local yinfu_mark = fk.CreateTriggerSkill{
    name = "#ysch4_yinfu_mark",
    refresh_events = {fk.TurnStart},
    global = true,
    can_refresh = function(self, event, target, player, data)
        return true
    end,
    on_refresh = function(self, event, target, player, data)
        player.room:setPlayerMark(player, self.name, {player.hp, player:getHandcardNum(), #player.player_cards[Player.Equip]})
    end,
}
yangzhiyangyan:addSkill(yinfu)
Fk:addSkill(yinfu_mark)
local maihuo = fk.CreateTriggerSkill{
    name = "ysch4_maihuo",
    frequency = Skill.Compulsory,
    events = {fk.TargetConfirmed},
    can_trigger = function (self, event, target, player, data)
        local mark = player:getTableMark("@[maihuo]ysch4_yinfu")
        if player:hasSkill(self.name) and #mark > 0 and target == player then
            if data.card.color == Card.Red then
                return player:getMark(self.name) == 0
            elseif data.card.color == Card.Black then
                return player:getMark(self.name) ~= 0
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark("@[maihuo]ysch4_yinfu")
        local to = room:getPlayerById(mark[#mark])
        if player:getMark(self.name) == 0 then
            if to.general ~= "hiddenone" and ((to.deputyGeneral ~= "" and to.deputyGeneral ~= "hiddenone") or not to.deputyGeneral ~= "" ) then
                DIYEnterHidden(to)
            end
        else
            to:turnOver()
        end
    end,

    refresh_events = {fk.AfterDrawPileShuffle},
    can_refresh = function(self, event, target, player, data)
        return player:hasSkill(self, true)
    end,
    on_refresh = function(self, event, target, player, data)
        player.room:setPlayerMark(player, self.name, 1)
    end,
    attached_skill_name = "ysch4_maihuo_equip&",
}
local maihuo_equip = fk.CreateActiveSkill{
    name = "ysch4_maihuo_equip&",
    anim_type = "support",
    prompt = "#ysch4_maihuo_equip&-active",
    card_num = 1,
    target_num = 1,
    card_filter = function(self, to_select, selected)
        return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeEquip and
        Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
    end,
    target_filter = function(self, to_select, selected, selected_cards)
        return #selected == 0 and #selected_cards == 1 and to_select ~= Self.id and
        Fk:currentRoom():getPlayerById(to_select):hasSkill("ysch4_maihuo")
    end,
    mute = true,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        local card = Fk:getCardById(effect.cards[1])
        room:notifySkillInvoked(target,"ysch4_maihuo","control")
        local use = {
            card = card,
            from = player.id,
            tos = {{target.id}},
            extraUse = true,
        }
        room:useCard(use)
    end,
}
Fk:addSkill(maihuo_equip)
yangzhiyangyan:addSkill(maihuo)
Fk:loadTranslationTable{
    ["ysch4_yinfu"] = "荫福",
    [":ysch4_yinfu"] = "每个回合结束时，若你的体力值或手牌数或装备区内的牌数大于本回合开始时，你可以令一名角色视为使用【树上开花】。此牌结算后，你可以令此前使用过【树上开花】的另一名角色获得本次被弃置的牌。",
    ["#ysch4_yinfu-invoke"] = "荫福：你可以令一名角色视为使用【树上开花】",
    ["#ysch4_yinfu-gain"] = "荫福：你可以令一名其他角色获得本次弃置牌",
    ["@[maihuo]ysch4_yinfu"] = "荫福",
    ["ysch4_maihuo"] = "埋祸",
    [":ysch4_maihuo"] = "锁定技，你是其他角色使用装备牌的合法目标；当你成为红色/黑色牌的目标后，若牌堆未洗切/已洗切过，上一名因“荫福”获得牌的角色隐匿/翻面。",
    ["ysch4_maihuo_equip&"] = "埋祸",
    [":ysch4_maihuo_equip&"] = "你可以对 杨芷杨艳 使用装备牌。",
    ["#ysch4_maihuo_equip&-active"] = "埋祸：你可以对 杨芷杨艳 使用装备牌",
}
local quanhuijie = General:new(extension, "ysch4__quanhuijie", "wu", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__quanhuijie"] = "全惠解",
    ["#ysch4__quanhuijie"] = "雪满梢头",
    ["designer:ysch4__quanhuijie"] = "我来为天地正秋风",
    ["cv:ysch4__quanhuijie"] = "佚名",
    ["illustrator:ysch4__quanhuijie"] = "游漫美绘",
}
local cijing = fk.CreateTriggerSkill{
    name = "ysch4_cijing",
    events = {fk.AfterCardsMove},
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            local suits = player:getTableMark("@[suits]ysch4_cijing-turn")
            local cards = {}
            for _, move in ipairs(data) do
                if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonUse then
                    local parent_event = player.room.logic:getCurrentEvent().parent
                    if parent_event ~= nil then
                        local card_ids = {}
                        if parent_event.event == GameEvent.UseCard then
                            local use = parent_event.data[1]
                            if use.from == player.id then
                                parent_event:searchEvents(GameEvent.MoveCards, 1, function(e2)
                                    if e2.parent and e2.parent.id == parent_event.id then
                                        for _, move2 in ipairs(e2.data) do
                                            if (move2.moveReason == fk.ReasonUse or move2.moveReason == fk.ReasonResonpse) then
                                                for _, info in ipairs(move2.moveInfo) do
                                                    if not table.contains(suits, Fk:getCardById(info.cardId).suit) then
                                                        table.insert(card_ids,info.cardId)
                                                    end
                                                end
                                            end
                                        end
                                    end
                                end)
                            end
                        end
                        if #card_ids > 0 then
                            for _, info in ipairs(move.moveInfo) do
                                if table.contains(card_ids, info.cardId) and info.fromArea == Card.Processing then
                                    table.insertIfNeed(cards, info.cardId)
                                end
                            end
                        end
                    end
                end
            end
            cards = table.filter(cards, function (id)
                return table.contains(player.room.discard_pile, id)
            end)
            cards = U.moveCardsHoldingAreaCheck(player.room, cards)
            if #cards > 0 then
                for _, id in ipairs(cards) do
                    table.insert(suits, Fk:getCardById(id).suit)
                end
                self.cost_data = cards
                player.room:setPlayerMark(player,"@[suits]ysch4_cijing-turn",suits)
                return true
            end
        end
    end,
    frequency = Skill.Compulsory,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local ids = self.cost_data
        room:moveCards{
            ids = ids,
            toArea = Card.DrawPile,
            moveReason = fk.ReasonJustMove,
            skillName = self.name,
            drawPilePosition = -1,
            moveVisible = true,
            proposer = player.id,
        }
    end,
}
cijing.CenterArea = true
local cijing_prohibit = fk.CreateProhibitSkill{
    name = "#ysch4_cijing_prohibit",
    prohibit_use = function(self, player, card)
        if not player:hasSkill("ysch4_cijing") or not card then return end
        local suits = {}
        for _, id in ipairs(Fk:currentRoom():getBanner("@$CenterArea")) do
            table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        table.removeOne(suits, Card.NoSuit)
        return table.contains(suits, card.suit)
    end,
    is_prohibited = function(self, from, to, card)
        local suits = {}
        for _, id in ipairs(Fk:currentRoom():getBanner("@$CenterArea")) do
            table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        table.removeOne(suits, Card.NoSuit)
        return to:hasSkill("ysch4_cijing") and table.contains(suits, card.suit)
    end,
}
cijing:addRelatedSkill(cijing_prohibit)
quanhuijie:addSkill(cijing)
local cishu = fk.CreateViewAsSkill{
    name = "ysch4_cishu",
    anim_type = "drawcard",
    pattern = "ysch_Al__bogus_flower",
    card_num = 0,
    card_filter = Util.FalseFunc,
    prompt = "#ysch4_cishu-card",
    view_as = function (self, cards, player)
        local card = Fk:cloneCard("ysch_Al__bogus_flower")
        card.skillName = self.name
        return card
    end,
    enabled_at_play = function (self, player)
        local suits = {}
        for _, id in ipairs(Fk:currentRoom():getBanner("@$CenterArea")) do
            table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        table.removeOne(suits, Card.NoSuit)
        return #suits < 4
    end,
    enabled_at_response = function (self, player, response)
        local suits = {}
        for _, id in ipairs(Fk:currentRoom():getBanner("@$CenterArea")) do
            table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        table.removeOne(suits, Card.NoSuit)
        return not response and #suits < 4
    end,
}
local cishu_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_cishu_trigger",
    anim_type = "drawcard",
    main_skill = cishu,
    mute = true,
    events = {fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        local suits = {}
        for _, id in ipairs(Fk:currentRoom():getBanner("@$CenterArea")) do
            table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        table.removeOne(suits, Card.NoSuit)
        return player:hasSkill("ysch4_cishu") and #suits == 4
    end,
    on_cost = function (self, event, target, player, data)
        local cards = {}
        for _, id in ipairs(Fk:currentRoom():getBanner("@$CenterArea")) do
            local card = Fk:getCardById(id)
            if card.type == Card.TypeEquip then
                table.insertIfNeed(cards, id)
            end
        end
        if #cards > 0 then
            local card, result = U.askforChooseCardsAndChoice(player, cards, {"OK"}, self.name, "#ysch4_cishu-prey", {"Cancel"})
            if result == "OK" then
                self.cost_data = card
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:notifySkillInvoked(player,"ysch4_cishu","drawcard")
        room:obtainCard(player, self.cost_data, true, fk.ReasonJustMove, player.id, self.name)
    end,
}
cishu:addRelatedSkill(cishu_trigger)
quanhuijie:addSkill(cishu)
Fk:loadTranslationTable{
    ["ysch4_cijing"] = "辞镜",
    [":ysch4_cijing"] = "锁定技，你不能成为花色存在于本回合弃牌堆的牌的使用者或目标。每回合每种花色的牌首次因你使用进入弃牌堆时，改为置于牌堆底。",
    ["@[suits]ysch4_cijing-turn"] = "辞镜",
    ["ysch4_cishu"] = "辞树",
    [":ysch4_cishu"] = "若本回合弃牌堆没有四种花色，你可视为使用【树上开花】。本回合弃牌堆存在所有花色的回合结束时，你可获得其中一张装备牌。",
    ["#ysch4_cishu_trigger"] = "辞树",
    ["#ysch4_cishu-card"] = "辞树：你可以视为使用【树上开花】",
    ["#ysch4_cishu-prey"] = "辞树：你可以获得其中一张牌",
}
local maoqi = General:new(extension, "ysch4__maoqi", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__maoqi"] = "毛奇",
    ["#ysch4__maoqi"] = "铁翼雄韬",
    ["designer:ysch4__maoqi"] = "昆世",
    ["cv:ysch4__maoqi"] = "佚名",
    ["illustrator:ysch4__maoqi"] = "未知",
}
local fenyipodi = fk.CreateActiveSkill{
    name = "ysch4_fenyipodi",
    mute = true,
    prompt = function (self, selected_cards, selected_targets)
        if self.interaction.data == "@@ysch4_fenyipodi2-inhand" then
            return "#ysch4_fenyipodi-zhiheng"
        else
            return "#ysch4_fenyipodi-luanji"
        end
    end,
    interaction = function (self, player)
        local choices = {}
        local mark = player:getTableMark("ysch4_fenyipodi")
        if #mark < 3 then
            mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
        end
        if player:usedSkillTimes("ex__zhiheng", Player.HistoryPhase) == 0 and table.contains(mark,"@@ysch4_fenyipodi2-inhand") then
            table.insert(choices,"@@ysch4_fenyipodi2-inhand")
        end
        if table.contains(mark,"@@ysch4_fenyipodi3-inhand") then
            table.insert(choices,"@@ysch4_fenyipodi3-inhand")
        end
        if #choices == 0 then return end
        return UI.ComboBox {choices = choices}
    end,
    target_filter = Util.FalseFunc,
    card_filter = function(self, to_select, selected)
        local card = Fk:getCardById(to_select)
        if card:getMark(self.interaction.data) > 0 then
            if self.interaction.data == "@@ysch4_fenyipodi2-inhand" then
                return not Self:prohibitDiscard(card)
            else
                if #selected == 1 then
                    return table.contains(Self:getHandlyIds(), to_select) and card.suit == Fk:getCardById(selected[1]).suit
                elseif #selected == 2 then
                    return false
                end
                return table.contains(Self:getHandlyIds(), to_select)
            end
        end
    end,
    can_use = function (self, player, card, extra_data)
        local mark = player:getTableMark("ysch4_fenyipodi")
        if #mark < 3 then
            mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
        end
        return (player:usedSkillTimes("ex__zhiheng", Player.HistoryPhase) == 0 and table.contains(mark,"@@ysch4_fenyipodi2-inhand")) or table.contains(mark,"@@ysch4_fenyipodi3-inhand")
    end,
    feasible = function (self, selected, selected_cards, player)
        if self.interaction.data == "@@ysch4_fenyipodi2-inhand" then
            return #selected_cards > 0
        else
            return #selected_cards == 2
        end
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        if self.interaction.data == "@@ysch4_fenyipodi2-inhand" then
            room:notifySkillInvoked(player,self.name,"drawcard")
            player:setSkillUseHistory("ex__zhiheng", player:usedSkillTimes("ex__zhiheng", Player.HistoryPhase) + 1, Player.HistoryPhase)
            local hand = player:getCardIds(Player.Hand)
            local more = #hand > 0
            for _, id in ipairs(hand) do
                if not table.contains(effect.cards, id) then
                    more = false
                    break
                end
            end
            room:throwCard(effect.cards, self.name, player, player)
            if not player.dead then
                room:drawCards(player, #effect.cards + (more and 1 or 0), self.name)
            end
        else
            room:notifySkillInvoked(player,self.name,"offensive")
            local card = Fk:cloneCard("archery_attack")
            card:addSubcards(effect.cards)
            card.skillName = "luanji"
            local use = {
                from = player.id,
                card = card,
            }
            room:useCard(use)
        end
    end,
    on_acquire = function (self, player, is_start)
        local mark = player:getTableMark(self.name)
        if #mark < 3 then
            mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
            --mark = {"@@ysch4_guilveqifeng1-inhand","@@ysch4_guilveqifeng2-inhand","@@ysch4_guilveqifeng3-inhand"}
            --mark = {"@@ysch4_guilveqifeng4-inhand","@@ysch4_guilveqifeng5-inhand","@@ysch4_guilveqifeng6-inhand"}
        end
        player.room:setPlayerMark(player,self.name,mark)
        player.room:setPlayerMark(player,"@ysch4_fenyipodi",table.concat(table.map(mark,function (v)
            return Fk:translate(v,"zh_CN")
        end)," "))
    end,
}
local fenyipodi_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_fenyipodi_trigger",
    events = {fk.AfterCardsMove,fk.GameStart},
    mute = true,
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill("ysch4_fenyipodi") then
            if event == fk.GameStart then
                return not player:isKongcheng()
            else
                if not table.find(player:getCardIds("h"), function(id) return Fk:getCardById(id):getMark("@@ysch4_fenyipodi1-inhand") > 0 end) then
                    for _, move in ipairs(data) do
                        if move.from == player.id then
                            if move.extra_data and move.extra_data.ysch4_fenyipodi then
                                self.cost_data = "lianying"
                                return true
                            end
                        end
                    end
                end
                local get = {}
                for _, move in ipairs(data) do
                    if move.toArea == Card.PlayerHand and move.to == player.id then
                        for _, info in ipairs(move.moveInfo) do
                            table.insertIfNeed(get, info.cardId)
                        end
                    end
                end
                if #get > 0 then
                    self.cost_data = {}
                    return true
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local cards = {}
        if event == fk.GameStart then
            cards = player.player_cards[Player.Hand]
        else
            if self.cost_data == "lianying" then
                return true
            else
                for _, move in ipairs(data) do
                    if move.toArea == Card.PlayerHand and move.to == player.id then
                        for _, info in ipairs(move.moveInfo) do
                            table.insertIfNeed(cards, info.cardId)
                        end
                    end
                end
            end
        end
        local mark = player:getTableMark("ysch4_fenyipodi")
        if #mark < 3 then
            mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
        end
        local markedcards = {{}, {}, {}}
        local card
        for _, id in ipairs(cards) do
            card = Fk:getCardById(id)
            for i = 1, 3, 1 do
                if card:getMark(mark[i]) > 0 then
                    table.insert(markedcards[i], id)
                    break
                end
            end
        end
        local result = room:askForCustomDialog(player, self.name,
            "packages/ysch_Al/qml/FenyipodiBox.qml", {
            cards,
            markedcards[1], mark[1],
            markedcards[2], mark[2],
            markedcards[3], mark[3],
        })
        if result ~= "" then
            self.cost_data = {cards,result}
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if self.cost_data == "lianying" then
            room:notifySkillInvoked(player,"ysch4_fenyipodi","drawcard")
            player:drawCards(1, "ysch4_fenyipodi")
        else
            local cards = self.cost_data[1]
            local result = self.cost_data[2]
            local card
            local mark = player:getTableMark("ysch4_fenyipodi")
            if #mark < 3 then
                mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
            end
            room:notifySkillInvoked(player,"ysch4_fenyipodi","control")
            if result ~= "" then
                local d = json.decode(result)
                for _, id in ipairs(cards) do
                    card = Fk:getCardById(id)
                    for i = 1, 3, 1 do
                        room:setCardMark(card, mark[i], table.contains(d[i], id) and 1 or 0)
                    end
                end
            end
        end
    end,

    refresh_events = {fk.BeforeCardsMove},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill("ysch4_fenyipodi")
    end,
    on_refresh = function (self, event, target, player, data)
        for _, move in ipairs(data) do
            if move.from == player.id then
                for _, info in ipairs(move.moveInfo) do
                    if info.fromArea == Card.PlayerHand and Fk:getCardById(info.cardId):getMark("@@ysch4_fenyipodi1-inhand") > 0 then
                        move.extra_data = move.extra_data or {}
                        move.extra_data.ysch4_fenyipodi = true
                        break
                    end
                end
            end
        end
    end,
}
fenyipodi:addRelatedSkill(fenyipodi_trigger)
maoqi:addSkill(fenyipodi)
local guilveqifeng = fk.CreateActiveSkill{
    name = "ysch4_guilveqifeng",
    mute = true,
    prompt = function (self, selected_cards, selected_targets)
        if table.contains({"1","2","3"}, string.sub(self.interaction.data,21,21)) then
            return "#ysch4_guilveqifeng-qice"
        else
            return "#ysch4_guilveqifeng-duwu"
        end
    end,
    interaction = function (self, player)
        local choices = {}
        local mark = player:getTableMark("ysch4_fenyipodi")
        if #mark < 3 then
            mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
        end
        if player:usedSkillTimes("qice", Player.HistoryPhase) == 0 and
        (table.contains(mark,"@@ysch4_guilveqifeng1-inhand") or table.contains(mark,"@@ysch4_guilveqifeng2-inhand") or table.contains(mark,"@@ysch4_guilveqifeng3-inhand")) and
        table.find(player:getCardIds("h"), function(id)
            return Fk:getCardById(id):getMark("@@ysch4_guilveqifeng1-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng2-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng3-inhand") > 0
        end) then
            table.insert(choices,"@@ysch4_guilveqifeng1-inhand")
        end
        if table.contains(mark,"@@ysch4_guilveqifeng4-inhand") or table.contains(mark,"@@ysch4_guilveqifeng5-inhand") or table.contains(mark,"@@ysch4_guilveqifeng6-inhand") then
            table.insert(choices,"@@ysch4_guilveqifeng4-inhand")
        end
        if #choices == 0 then return end
        return UI.ComboBox {choices = choices}
    end,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        if table.contains({"1","2","3"}, string.sub(self.interaction.data,21,21)) then
            return false
        else
            if #selected == 0 and to_select ~= Self.id then
                local target = Fk:currentRoom():getPlayerById(to_select)
                if target.hp == #selected_cards then
                    if table.contains(selected_cards, Self:getEquipment(Card.SubtypeWeapon)) then
                        return Self:distanceTo(target) == 1  --FIXME: some skills(eg.gongqi, meibu) add attackrange directly!
                    else
                        return Self:inMyAttackRange(target)
                    end
                end
            end
        end
    end,
    card_filter = function(self, to_select, selected)
        if table.contains({"1","2","3"}, string.sub(self.interaction.data,21,21)) then
            return false
        else
            local card = Fk:getCardById(to_select)
            return not Self:prohibitDiscard(to_select) and
            (card:getMark("@@ysch4_guilveqifeng4-inhand") > 0 or card:getMark("@@ysch4_guilveqifeng5-inhand") > 0 or card:getMark("@@ysch4_guilveqifeng6-inhand") > 0)
        end
    end,
    can_use = function (self, player, card, extra_data)
        local mark = player:getTableMark("ysch4_fenyipodi")
        if #mark < 3 then
            mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
        end
        return ((table.contains(mark,"@@ysch4_guilveqifeng1-inhand") or table.contains(mark,"@@ysch4_guilveqifeng2-inhand") or table.contains(mark,"@@ysch4_guilveqifeng3-inhand")) and table.find(player:getCardIds("h"), function(id)
            return Fk:getCardById(id):getMark("@@ysch4_guilveqifeng1-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng2-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng3-inhand") > 0
        end) and player:usedSkillTimes("qice", Player.HistoryPhase) == 0) or
        (table.contains(mark,"@@ysch4_guilveqifeng4-inhand") or table.contains(mark,"@@ysch4_guilveqifeng5-inhand") or table.contains(mark,"@@ysch4_guilveqifeng6-inhand"))
    end,
    feasible = function (self, selected, selected_cards, player)
        if table.contains({"1","2","3"}, string.sub(self.interaction.data,21,21)) then
            return table.find(player:getCardIds("h"), function(id)
                return Fk:getCardById(id):getMark("@@ysch4_guilveqifeng1-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng2-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng3-inhand") > 0
            end)
        else
            return #selected == 1 and #selected_cards == Fk:currentRoom():getPlayerById(selected[1]).hp
        end
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        if table.contains({"1","2","3"}, string.sub(self.interaction.data,21,21)) then
            local success, dat = player.room:askForUseViewAsSkill(player, "ysch4_guilveqifeng-qice", "#ysch4_guilveqifeng-qice", false)
            if success and dat then
                player:setSkillUseHistory("qice", player:usedSkillTimes("qice", Player.HistoryPhase) + 1, Player.HistoryPhase)
                room:notifySkillInvoked(player,self.name,"special")
                local card = Fk.skills["ysch4_guilveqifeng-qice"]:viewAs(dat.cards,player)
                local use = {from = player.id, tos = table.map(dat.targets, function(p) return {p} end), card = card}
                room:useCard(use)
            end
        else
            local target = room:getPlayerById(effect.tos[1])
            room:notifySkillInvoked(player,self.name,"offensive",effect.tos)
            room:throwCard(effect.cards, self.name, player)
            if not target.dead then
                room:damage{
                    from = player,
                    to = target,
                    damage = 1,
                    skillName = self.name,
                }
            end
        end
    end,
}
local qice = fk.CreateViewAsSkill{
    name = "ysch4_guilveqifeng-qice",
    prompt = "#ysch4_guilveqifeng-qice",
    interaction = function()
        local all_names = getAllCardNames("t")
        return U.CardNameBox {
            choices = U.getViewAsCardNames(Self, "qice", all_names),
            all_choices = all_names,
            default_choice = "AskForCardsChosen"
        }
    end,
    card_filter = Util.FalseFunc,
    view_as = function(self, cards, player)
        if Fk.all_card_types[self.interaction.data] == nil then return end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcards(table.filter(player:getCardIds(Player.Hand),function (id)
            return Fk:getCardById(id):getMark("@@ysch4_guilveqifeng1-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng2-inhand") > 0 or Fk:getCardById(id):getMark("@@ysch4_guilveqifeng3-inhand") > 0
        end))
        card.skillName = self.name
        return card
    end,
    enabled_at_play = function(self, player)
        return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
    end,
}
Fk:addSkill(qice)
local guilveqifeng_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_guilveqifeng_trigger",
    mute = true,
    events = {fk.AfterCardsMove,fk.AfterSkillEffect},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill("ysch4_guilveqifeng") then
            local lianying = table.filter(player:getCardIds(Player.Hand),function (id)
                return Fk:getCardById(id):getMark("@@ysch4_fenyipodi1-inhand") > 0
            end)
            local zhiheng = table.filter(player:getCardIds(Player.Hand),function (id)
                return Fk:getCardById(id):getMark("@@ysch4_fenyipodi2-inhand") > 0
            end)
            local luanji = table.filter(player:getCardIds(Player.Hand),function (id)
                return Fk:getCardById(id):getMark("@@ysch4_fenyipodi3-inhand") > 0
            end)
            if event == fk.AfterCardsMove then
                for _, move in ipairs(data) do
                    if move.from == player.id then
                        if move.extra_data then
                            if move.extra_data.ysch4_fenyipodi_lianying then
                                return #lianying == (#zhiheng + #luanji)
                            end
                            if move.extra_data.ysch4_fenyipodi_zhiheng then
                                return #zhiheng == (#lianying + #luanji)
                            end
                            if move.extra_data.ysch4_fenyipodi_luanji then
                                return #luanji == (#lianying + #zhiheng)
                            end
                        end
                    end
                end
            else
                return data.name == "#ysch4_fenyipodi_trigger" and (#lianying == (#zhiheng + #luanji) or #zhiheng == (#lianying + #luanji) or #luanji == (#lianying + #zhiheng))
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local lianying = table.filter(player:getCardIds(Player.Hand),function (id)
            return Fk:getCardById(id):getMark("@@ysch4_fenyipodi1-inhand") > 0
        end)
        local zhiheng = table.filter(player:getCardIds(Player.Hand),function (id)
            return Fk:getCardById(id):getMark("@@ysch4_fenyipodi2-inhand") > 0
        end)
        local luanji = table.filter(player:getCardIds(Player.Hand),function (id)
            return Fk:getCardById(id):getMark("@@ysch4_fenyipodi3-inhand") > 0
        end)
        local mark = player:getTableMark("ysch4_fenyipodi")
        if #mark < 3 then
            mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
        end
        local choices1, choices2 = {}, {"@@ysch4_guilveqifeng1-inhand","@@ysch4_guilveqifeng4-inhand","Cancel"}
        if #lianying == (#zhiheng + #luanji) and table.contains(mark,"@@ysch4_fenyipodi1-inhand") then
            table.insertIfNeed(choices1,"@@ysch4_fenyipodi1-inhand")
        end
        if #zhiheng == (#lianying + #luanji) and table.contains(mark,"@@ysch4_fenyipodi2-inhand") then
            table.insertIfNeed(choices1,"@@ysch4_fenyipodi2-inhand")
        end
        if #luanji == (#lianying + #zhiheng) and table.contains(mark,"@@ysch4_fenyipodi3-inhand") then
            table.insertIfNeed(choices1,"@@ysch4_fenyipodi3-inhand")
        end
        if #choices1 > 0 then
            table.insertIfNeed(choices1,"Cancel")
            while true do
                local choice = room:askForChoice(player,choices1,self.name,"#ysch4_guilveqifeng-prompt1")
                if choice ~= "Cancel" then
                    local change = room:askForChoice(player,choices2,self.name,"#ysch4_guilveqifeng-prompt2:::"..choice)
                    if change ~= "Cancel" then
                        self.cost_data = {choice,change}
                        return true
                    end
                else
                    break
                end
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local before,after = self.cost_data[1],self.cost_data[2]
        local num1,num2 = tonumber(string.sub(before,18,18)),tonumber(string.sub(after,21,21))
        after = "@@ysch4_guilveqifeng"..tostring(num2 + num1 - 1).."-inhand"
        local beforeMark,afterMark = player:getTableMark("ysch4_fenyipodi"), {}
        if #beforeMark < 3 then
            beforeMark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
        end
        for _, value in ipairs(beforeMark) do
            if value == before then
                table.insert(afterMark,after)
            else
                table.insert(afterMark,value)
            end
        end
        room:notifySkillInvoked(player,"ysch4_guilveqifeng","control")
        room:setPlayerMark(player,"ysch4_fenyipodi",afterMark)
        room:setPlayerMark(player,"@ysch4_fenyipodi",table.concat(table.map(afterMark,function (v)
            return Fk:translate(v,"zh_CN")
        end)," "))
        local cards = player.player_cards[Player.Hand]
        for _, id in ipairs(cards) do
            local card = Fk:getCardById(id)
            if card:getMark(before) > 0 then
                room:setCardMark(card,before,0)
                room:setCardMark(card,after,1)
            end
        end
    end,

    refresh_events = {fk.BeforeCardsMove,fk.DamageCaused, fk.DamageInflicted},
    can_refresh = function (self, event, target, player, data)
        if player:hasSkill("ysch4_fenyipodi") then
            if event == fk.BeforeCardsMove then
                return true
            else
                return target == player
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        if event == fk.BeforeCardsMove then
            for _, move in ipairs(data) do
                if move.from == player.id then
                    for _, info in ipairs(move.moveInfo) do
                        if info.fromArea == Card.PlayerHand then
                            if Fk:getCardById(info.cardId):getMark("@@ysch4_fenyipodi1-inhand") > 0 then
                                move.extra_data = move.extra_data or {}
                                move.extra_data.ysch4_fenyipodi_lianying = true
                            elseif Fk:getCardById(info.cardId):getMark("@@ysch4_fenyipodi2-inhand") > 0 then
                                move.extra_data = move.extra_data or {}
                                move.extra_data.ysch4_fenyipodi_zhiheng = true
                            elseif Fk:getCardById(info.cardId):getMark("@@ysch4_fenyipodi3-inhand") > 0 then
                                move.extra_data = move.extra_data or {}
                                move.extra_data.ysch4_fenyipodi_luanji = true
                            end
                        end
                    end
                end
            end
        else
            local room = player.room
            local beforeMark,afterMark = player:getTableMark("ysch4_fenyipodi"), {}
            local mark = {"@@ysch4_fenyipodi1-inhand","@@ysch4_fenyipodi2-inhand","@@ysch4_fenyipodi3-inhand"}
            if event == fk.DamageCaused then
                for index, value in ipairs(beforeMark) do
                    if table.contains({"@@ysch4_guilveqifeng4-inhand","@@ysch4_guilveqifeng5-inhand","@@ysch4_guilveqifeng6-inhand"},value) then
                        table.insert(afterMark,mark[index])
                    else
                        table.insert(afterMark,value)
                    end
                end
            else
                for index, value in ipairs(beforeMark) do
                    if table.contains({"@@ysch4_guilveqifeng1-inhand","@@ysch4_guilveqifeng2-inhand","@@ysch4_guilveqifeng3-inhand"},value) then
                        table.insert(afterMark,mark[index])
                    else
                        table.insert(afterMark,value)
                    end
                end
            end
            room:setPlayerMark(player,"ysch4_fenyipodi",afterMark)
            room:setPlayerMark(player,"@ysch4_fenyipodi",table.concat(table.map(afterMark,function (v)
                return Fk:translate(v,"zh_CN")
            end)," "))
            local cards = player.player_cards[Player.Hand]
            for _, id in ipairs(cards) do
                local card = Fk:getCardById(id)
                for index, value in ipairs(beforeMark) do
                    if card:getMark(value) > 0 and not table.contains(afterMark,value) then
                        room:setCardMark(card,value,0)
                        room:setCardMark(card,mark[index],1)
                    end
                end
            end
        end
    end,
}
guilveqifeng:addRelatedSkill(guilveqifeng_trigger)
maoqi:addSkill(guilveqifeng)
Fk:loadTranslationTable{
    ["ysch4_fenyipodi"] = "分翼破敌",
    [":ysch4_fenyipodi"] = "你的手牌区依次分为：可发动“连营”区；可发动“制衡”区；可发动“乱击”区。你于获得牌时任意分配至以上区域。",
    ["#ysch4_fenyipodi"] = "分翼破敌：你可以将获得牌任意分配至以上区域",
    ["#ysch4_fenyipodi-zhiheng"] = "分翼破敌：是否发动 制衡，弃置任意张牌并摸等量的牌，若弃置了所有的手牌，多摸一张牌",
    ["#ysch4_fenyipodi-luanji"] = "分翼破敌：是否发动 乱击，将两张相同花色的手牌当【万箭齐发】使用",
    ["#ysch4_fenyipodi_trigger"] = "分翼破敌",
    ["@ysch4_fenyipodi"] = "",
    ["@@ysch4_fenyipodi1-inhand"] = "连营",
    ["@@ysch4_fenyipodi2-inhand"] = "制衡",
    ["@@ysch4_fenyipodi3-inhand"] = "乱击",
    ["ysch4_guilveqifeng"] = "轨略奇锋",
    [":ysch4_guilveqifeng"] = "你的一个初始手牌区牌数为其余初始手牌区之和时你可以将之改为可发动“奇策”/“黩武”直至你下一次造成/受到伤害。",
    ["#ysch4_guilveqifeng-qice"] = "轨略奇锋：是否发动 奇策，将所有的手牌当任意普通锦囊牌使用。",
    ["#ysch4_guilveqifeng-duwu"] = "轨略奇锋：是否发动 黩武，弃置X张牌对你攻击范围内的一名其他角色造成1点伤害（X为该角色的体力值）",
    ["#ysch4_guilveqifeng_trigger"] = "轨略奇锋",
    ["#ysch4_guilveqifeng-prompt1"] = "是否发动 轨略奇锋，修改一个手牌区域",
    ["#ysch4_guilveqifeng-prompt2"] = "轨略奇锋：请你选择要将 %arg区 修改成的区域，或点“取消”重新选择区域",
    ["ysch4_guilveqifeng-qice"] = "奇策",
    [":ysch4_guilveqifeng-qice"] = "出牌阶段限一次，你可以将所有的手牌当任意普通锦囊牌使用。",
    ["@@ysch4_guilveqifeng1-inhand"] = "奇策",
    ["@@ysch4_guilveqifeng2-inhand"] = "奇策",
    ["@@ysch4_guilveqifeng3-inhand"] = "奇策",
    ["@@ysch4_guilveqifeng4-inhand"] = "黩武",
    ["@@ysch4_guilveqifeng5-inhand"] = "黩武",
    ["@@ysch4_guilveqifeng6-inhand"] = "黩武",
}
--[[local lishimin = General:new(extension, "ysch4__lishimin", "tang", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__lishimin"] = "李世民",
    ["#ysch4__lishimin"] = "龙凤神武",
    ["designer:ysch4__lishimin"] = "伶伶",
    ["cv:ysch4__lishimin"] = "佚名",
    ["illustrator:ysch4__lishimin"] = "未知",
}
local mingshi = fk.CreateViewAsSkill{
    name = "ysch4_mingshi",
    pattern = "peach,slash,jink",
    card_filter = function(self, to_select, selected, player)
        return #selected < 2
    end,
    interaction = function(self, player)
        local choices = {}
        for _, name in ipairs({"peach","slash","jink"}) do
            local card = Fk:cloneCard(name)
            if player:getMark("ysch4_mingshi_"..name.."-round") == 0 and (((Fk.currentResponsePattern == nil and player:canUse(card)) or
            (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)))) then
                table.insertIfNeed(choices, name)
            end
        end
        if #choices == 0 then return false end
        return UI.ComboBox { choices = choices }
    end,
    view_as = function(self, cards)
        if #cards ~= 2 or not self.interaction.data then return nil end
        local c = Fk:cloneCard(self.interaction.data)
        c.skillName = self.name
        c:addSubcards(cards)
        return c
    end,
    after_use = function (self, player, use)
        local name = use.card.trueName
        player.room:setPlayerMark(player,"ysch4_mingshi_"..name.."-round",1)
        player.room:setPlayerMark(player,"@@ysch4_mingshi_"..name.."-round",1)
    end,
    enabled_at_play = function (self, player)
        local choices = {}
        for _, name in ipairs({"peach","slash","jink"}) do
            if player:getMark("ysch4_mingshi_"..name.."-round") == 0 then
                table.insertIfNeed(choices, name)
            end
        end
        return #choices > 0
    end,
    enabled_at_response = function (self, player, response)
        if Fk.currentResponsePattern then
            for _, name in ipairs({"peach","slash","jink"}) do
                local card = Fk:cloneCard(name)
                if Exppattern:Parse(Fk.currentResponsePattern):match(card) then
                    if player:getMark("ysch4_mingshi_"..name.."-round") == 0 then
                        return true
                    end
                end
            end
        end
    end,
}
local mingshi_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_mingshi_trigger",
    refresh_events = {fk.Damage,fk.Damaged,fk.HpRecover},
    can_refresh = function (self, event, target, player, data)
        if target == player then
            if event == fk.Damage then
                return player:getMark("@@ysch4_mingshi_slash-round") > 0
            elseif event == fk.Damaged then
                return player:getMark("@@ysch4_mingshi_jink-round") > 0
            else
                return player:getMark("@@ysch4_mingshi_peach-round") > 0
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.Damage then
            room:setPlayerMark(player,"@@ysch4_mingshi_slash-round",0)
        elseif event == fk.Damaged then
            room:setPlayerMark(player,"@@ysch4_mingshi_jink-round",0)
        else
            room:setPlayerMark(player,"@@ysch4_mingshi_peach-round",0)
        end
        player:drawCards(3,"ysch4_mingshi")
        local choices,all_choices = {},{}
        for _, skill in ipairs(player.player_skills) do
            if skill.frequency == Skill.Limited then
                table.insertIfNeed(all_choices, skill.name)
                if player:usedSkillTimes(skill.name, Player.HistoryGame) > 0 then
                    table.insertIfNeed(choices, skill.name)
                end
            end
        end
        if #choices == #all_choices then
            local skill = table.random(choices)
            player:setSkillUseHistory(skill, 0, Player.HistoryGame)
        end
    end,
}
mingshi:addRelatedSkill(mingshi_trigger)
lishimin:addSkill(mingshi)
local duomeng = fk.CreateViewAsSkill{
    name = "ysch4_duomeng",
    frequency = Skill.Limited,
    anim_type = "offensive",
    pattern = "archery_attack",
    card_filter = Util.FalseFunc,
    prompt = "#ysch4_duomeng",
    view_as = function(self, cards)
        local c = Fk:cloneCard("archery_attack")
        c.skillName = self.name
        return c
    end,
    enabled_at_play = function (self, player)
        return player:usedSkillTimes(self.name,Player.HistoryGame) == 0
    end,
}
lishimin:addSkill(duomeng)
local dishu = fk.CreateViewAsSkill{
    name = "ysch4_dishu",
    frequency = Skill.Limited,
    anim_type = "offensive",
    pattern = "sincere_treat",
    card_filter = Util.FalseFunc,
    prompt = "#ysch4_dishu",
    view_as = function(self, cards)
        local c = Fk:cloneCard("sincere_treat")
        c.skillName = self.name
        return c
    end,
    enabled_at_play = function (self, player)
        return player:usedSkillTimes(self.name,Player.HistoryGame) == 0
    end,
}
lishimin:addSkill(dishu)
local zhenguan = fk.CreateViewAsSkill{
    name = "ysch4_zhenguan",
    frequency = Skill.Limited,
    anim_type = "offensive",
    pattern = "god_salvation",
    card_filter = Util.FalseFunc,
    prompt = "#ysch4_zhenguan",
    view_as = function(self, cards)
        local c = Fk:cloneCard("god_salvation")
        c.skillName = self.name
        return c
    end,
    enabled_at_play = function (self, player)
        return player:usedSkillTimes(self.name,Player.HistoryGame) == 0
    end,
}
lishimin:addSkill(zhenguan)
Fk:loadTranslationTable{
    ["ysch4_mingshi"] = "命世",
    [":ysch4_mingshi"] = "每轮各限一次，你可以将两张牌当【杀】/【闪】/【桃】使用或打出，则本轮你下一次造成伤害/受到伤害/回复体力后，你摸三张牌，然后若你限定技皆已行置，则随机重置一个。",
    ["@@ysch4_mingshi_slash-round"] = "命世 造成伤害",
    ["@@ysch4_mingshi_jink-round"] = "命世 受到伤害",
    ["@@ysch4_mingshi_peach-round"] = "命世 回复体力",
    ["ysch4_duomeng"] = "夺门",
    [":ysch4_duomeng"] = "限定技，出牌阶段，你可以视为使用【万箭齐发】。",
    ["#ysch4_duomeng"] = "夺门：你可以视为使用【万箭齐发】。",
    ["ysch4_dishu"] = "帝术",
    [":ysch4_dishu"] = "限定技，出牌阶段，你可以视为使用【推心置腹】。",
    ["#ysch4_dishu"] = "帝术：你可以视为使用【推心置腹】。",
    ["ysch4_zhenguan"] = "贞观",
    [":ysch4_zhenguan"] = "限定技，出牌阶段，你可以视为使用【桃园结义】。",
    ["#ysch4_zhenguan"] = "贞观：你可以视为使用【桃园结义】。",
}]]--
local liyuanba = General:new(extension, "ysch4__liyuanba", "tang", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__liyuanba"] = "李元霸",
    ["#ysch4__liyuanba"] = "兼资武武",
    ["designer:ysch4__liyuanba"] = "廷玉",
    ["cv:ysch4__liyuanba"] = "佚名",
    ["illustrator:ysch4__liyuanba"] = "未知",
}
local wuji = fk.CreateTriggerSkill{
    name = "ysch4_wuji",
    anim_type = "offensive",
    frequency = Skill.Compulsory,
    events = {fk.EventPhaseStart},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and player.phase == Player.Play and target == player
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local ids = table.map(room.alive_players,Util.IdMapper)
        local tos = table.random(ids,3)
        local doed = {}
        if (room:isGameMode("1v2_mode") or room:isGameMode("hell_combat_mode")) and table.contains(tos,player.id) then
            table.removeOne(tos,player.id)
            table.insert(tos,player.id)
        end
        player:chat("{emoji50}")
        player:broadcastSkillInvoke("fastchat_m",23)
        for index, id in ipairs(tos) do
            local loop = true
            for _, p in ipairs(room:getAlivePlayers()) do
                if #doed > 0 then
                    for _, cp in ipairs(doed) do
                        room:setEmotion(cp, "./image/anim/selected")
                    end
                end
                if not table.contains(doed,p) then
                    room:delay(350)
                    --room:setEmotion(p, "./packages/moepack/image/anim/question")
                    room:setEmotion(p, "./image/anim/selectable")
                    room:notifyMoveFocus(p, self.name)
                    if p.id == id and loop then
                        room:doIndicate(player.id, {id})
                        room:setEmotion(p, "./image/anim/selected")
                        table.insert(doed,p)
                        loop = false
                        if index == 3 then
                            break
                        end
                    end
                end
            end
        end
        if table.contains(tos,player.id) then
            player:chat("{emoji58}")
            player:broadcastSkillInvoke("fastchat_m",19)
            for _, id in ipairs(tos) do
                local p = room:getPlayerById(id)
                if not p.dead then
                    room:killPlayer{
                        who = id,
                        damage = {to = p, damage = 1, from = player},
                    }
                end
            end
        else
            for _, id in ipairs(tos) do
                local p = room:getPlayerById(id)
                if not p.dead then
                    room:damage{
                        from = player,
                        to = p,
                        damage = 1,
                        skillName = self.name,
                    }
                end
            end
        end
    end,

    refresh_events = {fk.EnterDying},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(self.name) and player == target
    end,
    on_refresh = function (self, event, target, player, data)
        local emoji = table.random({"{emoji9}","{emoji12}","{emoji14}","{emoji27}","{emoji51}"})
        player:chat(emoji)
        player:broadcastSkillInvoke("fastchat_m",table.random({2,4,5}))
    end,
}
liyuanba:addSkill(wuji)
Fk:loadTranslationTable{
    ["ysch4_wuji"] = "武极",
    [":ysch4_wuji"] = "锁定技，出牌阶段开始时，你将随机杀死三名角色，若不包括你，则改为你各对其造成1点伤害。",
}
local guanyu = General:new(extension, "ysch4__guanyu", "shu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__guanyu"] = "关羽",
    ["#ysch4__guanyu"] = "笑辟群萧",
    ["designer:ysch4__guanyu"] = "廷玉",
    ["cv:ysch4__guanyu"] = "佚名",
    ["illustrator:ysch4__guanyu"] = "未知",
}
local wusheng = fk.CreateTriggerSkill{
    name = "ysch4_wusheng",
    anim_type = "offensive",
    events = {fk.TurnStart},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room:getOtherPlayers(player), function (p)
            return not p:isKongcheng()
        end)
        if #targets == 0 then return false end
        local to = room:askForChoosePlayers(player,table.map(targets, Util.IdMapper),1,1,"#ysch4_wusheng-invoke",self.name,true)
        if #to > 0 then
            self.cost_data = to
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data[1])
        for i = 1, 3, 1 do
            if to:getHandcardNum() >= i then
                local cards = room:askForCardsChosen(player,to,i,i,"h",self.name,"#ysch4_wusheng-turnOver::"..to.id..":"..i)
                if #cards > 0 then
                    local show, hidden = {}, {}
                    for _, id in ipairs(cards) do
                        local card = Fk:getCardById(id)
                        if card:getMark("@@ShownCards-inhand") == 0 then
                            table.insert(show,card.id)
                            room:setCardMark(card,"@@ShownCards-inhand",1)
                        else
                            table.insert(hidden,card.id)
                            room:setCardMark(card,"@@ShownCards-inhand",0)
                        end
                    end
                    if #show > 0 then
                        room:sendLog{type = "#ysch4_show-log", from = player.id, card = show, arg = self.name, to = {to.id}}
                    end
                    if #hidden > 0 then
                        room:sendLog{type = "#ysch4_hidden-log", from = player.id, card = hidden, arg = self.name, to = {to.id}}
                    end
                    local showRed,hiddenBlack = false,false
                    for _, id in ipairs(show) do
                        local card = Fk:getCardById(id)
                        local slash = Fk:cloneCard("slash")
                        slash.skillName = self.name
                        if card.color == Card.Red and player:canUseTo(slash, to, { bypass_times = true, bypass_distances= true }) and showRed == false then
                            showRed = true
                            room:useCard{
                                from = player.id,
                                card = slash,
                                tos = { { to.id } },
                                extraUse = true,
                            }
                        end
                    end
                    for _, id in ipairs(hidden) do
                        local card = Fk:getCardById(id)
                        if card.color == Card.Black and hiddenBlack == false then
                            hiddenBlack = true
                            local tos = room:askForChoosePlayers(player,{player.id,to.id},1,1,"#ysch4_wusheng-prompt::"..to.id,self.name,true)
                            if #tos > 0 then
                                local cp = room:getPlayerById(tos[1])
                                local recast = {}
                                if tos[1] == player.id then
                                    recast = room:askForCard(player,1,999,true,self.name,true,".","#ysch4_wusheng-draw")
                                else
                                    recast = room:askForCardsChosen(player,cp,1,999,"he",self.name,"#ysch4_wusheng-recast::"..cp.id)
                                end
                                if #recast > 0 then
                                    room:recastCard(recast, cp, self.name)
                                end
                            end
                        end
                    end
                end
            end
        end
    end
}
guanyu:addSkill(wusheng)
local yijue = fk.CreateTriggerSkill{
    name = "ysch4_yijue",
    events = {fk.DamageCaused},
    anim_type = "negative",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target == player and data.damage >= data.to.hp and player:getHandcardNum() >= 4
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local cards = room:askForCardsChosen(data.to,player,4,4,"h",self.name,"#ysch4_yijue-invoke::"..player.id)
        if #cards > 0 then
            self.cost_data = cards
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local cards = self.cost_data
        local show, hidden = {}, {}
        for _, id in ipairs(cards) do
            local card = Fk:getCardById(id)
            if card:getMark("@@ShownCards-inhand") == 0 then
                table.insert(show,card.id)
                room:setCardMark(card,"@@ShownCards-inhand",1)
            else
                table.insert(hidden,card.id)
                room:setCardMark(card,"@@ShownCards-inhand",0)
            end
        end
        if #show > 0 then
            room:sendLog{type = "#ysch4_show-log", from = data.to.id, card = show, arg = self.name, to = {player.id}}
        end
        if #hidden > 0 then
            room:sendLog{type = "#ysch4_hidden-log", from = data.to.id, card = hidden, arg = self.name, to = {player.id}}
        end
        if #table.filter(player:getCardIds("h"),function (id)
            local card = Fk:getCardById(id)
            return card:getMark("@@ShownCards-inhand") ~= 0 and card.trueName == "slash"
        end) == 0 then
            return true
        end
    end,
}
guanyu:addSkill(yijue)
Fk:loadTranslationTable{
    ["ysch4_wusheng"] = "武圣",
    [":ysch4_wusheng"] = "回合开始时，你可以依次翻面一名其他角色的一，二，三张手牌。每明置一次红色牌，你便视为对其使用一张【杀】；每暗置一次黑色牌，你便可以重铸你或其任意张牌。",
    ["#ysch4_wusheng-invoke"] = "是否发动 武圣，依次翻面一名其他角色的一，二，三张手牌",
    ["#ysch4_wusheng-turnOver"] = "武圣：翻面 %dest %arg 张手牌",
    ["#ysch4_wusheng-prompt"] = "武圣：你可以重铸你或 %dest 的任意张牌",
    ["#ysch4_wusheng-draw"] = "武圣：你可以重铸任意张牌",
    ["#ysch4_wusheng-recast"] = "武圣：重铸 %dest 的任意张牌",
    ["#ysch4_show-log"] = "%from 因〖%arg〗明置了 %to 的 %card",
    ["#ysch4_hidden-log"] = "%from 因〖%arg〗暗置了 %to 的 %card",
    ["ysch4_yijue"] = "义绝",
    [":ysch4_yijue"] = "你造成致命伤害时，受伤角色可以翻面你四张手牌；若你没有明置【杀】，则防止之。",
    ["#ysch4_yijue-invoke"] = "义绝：是否翻面 %dest 的四张手牌；若其没有明置的【杀】，防止此伤害",

    ["$ysch4_wusheng1"] = "秉赤面，观春秋，虓菟踏纛，汗青著峥嵘！",
    ["$ysch4_wusheng2"] = "着青袍，饮温酒，五关已过，来将且通名！",
    ["$ysch4_yijue1"] = "春秋着墨十万卷，长髯映雪千里行。",
    ["$ysch4_yijue2"] = "义驱千里长路，风起桃园芳菲。",
    ["~ysch4__guanyu"] = "天下泪染将军袍，且枕青山梦桃园……",
}
local caorui = General:new(extension, "ysch4__caorui", "wei", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__caorui"] = "曹叡",
    ["#ysch4__caorui"] = "珠帘荒卷",
    ["designer:ysch4__caorui"] = "祭祀",
    ["cv:ysch4__caorui"] = "佚名",
    ["illustrator:ysch4__caorui"] = "漫想族",
}
local yihe = fk.CreateTriggerSkill{
    name = "ysch4_yihe",
    mute = true,
    events = {fk.TurnEnd,fk.HpRecover},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and (target == player or event == fk.TurnEnd) then
            local targets1,targets2 = {},{}
            player.room.logic:getActualDamageEvents(1, function (e)
                local damage = e.data[1]
                if not damage.to.dead then
                    table.insertIfNeed(targets2,damage.to.id)
                end
                if damage.to == player and damage.from and not damage.from.dead then
                    table.insertIfNeed(targets1,damage.from.id)
                end
            end, Player.HistoryRound)
            return #targets1 > 0 or #targets2 > 0
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local targets1,targets2 = {},{}
        player.room.logic:getActualDamageEvents(1, function (e)
            local damage = e.data[1]
            if not damage.to.dead then
                table.insertIfNeed(targets2,damage.to.id)
            end
            if damage.to == player and damage.from and not damage.from.dead then
                table.insertIfNeed(targets1,damage.from.id)
            end
        end, Player.HistoryRound)
        local choices = {}
        if #targets1 > 0 then table.insert(choices,"#ysch4_yihe1") end
        if #targets2 > 0 then table.insert(choices,"#ysch4_yihe2") end
        table.insert(choices,"Cancel")
        local choice = room:askForChoice(player,choices,self.name,"#ysch4_yihe-invoke",true,{"#ysch4_yihe1","#ysch4_yihe2","Cancel"})
        if choice ~= "Cancel" then
            self.cost_data = choice
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local min, max = 0, 5
        local targets1,targets2 = {},{}
        player.room.logic:getActualDamageEvents(1, function (e)
            local damage = e.data[1]
            if not damage.to.dead then
                table.insertIfNeed(targets2,damage.to.id)
            end
            if damage.to == player and damage.from and not damage.from.dead then
                table.insertIfNeed(targets1,damage.from.id)
            end
        end, Player.HistoryRound)
        if self.cost_data == "#ysch4_yihe1" then
            room:notifySkillInvoked(player,self.name,"control")
            room:setPlayerMark(player,"ysch4_yihe",targets1)
            for index, id in ipairs(targets1) do
                local tp = room:getPlayerById(id)
                local prompt = "#ysch4_yihe_discard:::"..max
                if index == #targets1 then
                    min = max
                    prompt = "#ysch4_yihe_discardMax:::"..max
                end
                local cards = room:askForDiscard(tp,min,max,true,self.name,false,".",prompt)
                max = max - #cards
                if max == 0 then
                    break
                end
            end
        else
            room:notifySkillInvoked(player,self.name,"drawcard")
            room:setPlayerMark(player,"ysch4_yihe",targets2)
            max = 3
            for index, id in ipairs(targets2) do
                local tp = room:getPlayerById(id)
                local choices = {}
                for i = 0, math.min(3, max), 1 do
                    table.insert(choices, "ysch4_yihe_draw" .. tostring(i))
                end
                if index == #targets2 then
                    choices = {"ysch4_yihe_draw" .. tostring(max)}
                end
                local choice = room:askForChoice(tp, choices, self.name, "#ysch4_yihe_draw:::"..max)
                local x = tonumber(string.sub(choice, 16, 16))
                if x >= 0 then
                    room:drawCards(tp, x, self.name) -- 危险
                end
                max = max - x
                if max == 0 then
                    break
                end
            end
        end
    end,

    refresh_events = {fk.Damaged},
    can_refresh = function (self, event, target, player, data)
        return player:hasSkill(self.name)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local targets1,targets2 = {},{}
        player.room.logic:getActualDamageEvents(1, function (e)
            local damage = e.data[1]
            if not damage.to.dead then
                table.insertIfNeed(targets2,damage.to.id)
            end
            if damage.to == player and damage.from and not damage.from.dead then
                table.insertIfNeed(targets1,damage.from.id)
            end
        end, Player.HistoryRound)
        if #targets1 > 0 then
            room:setPlayerMark(player,"@[player]ysch4_yihe_damage-round",targets1)
        end
        if #targets2 > 0 then
            room:setPlayerMark(player,"@[player]ysch4_yihe_damaged-round",targets2)
        end
    end,
}
caorui:addSkill(yihe)
local yiqing = fk.CreateTriggerSkill{
    name = "ysch4_yiqing",
    events = {fk.RoundEnd},
    frequency = Skill.Compulsory,
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and player:getMark("ysch4_yihe") ~= 0
    end,
    prompt = "#ysch4_yiqing",
    on_use = function (self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function(p) return (p == player or table.contains(player:getMark("ysch4_yihe"),p.id)) and not p:isKongcheng() end)
        local discussion = U.Discussion(player, targets, self.name)
        if discussion.color == "red" then
            for _, p in ipairs(targets) do
                if not p.dead and discussion.results[p.id].opinion ~= discussion.results[player.id].opinion then
                    room:damage({
                        from = player,
                        to = p,
                        damage = 1,
                        damageType = fk.NormalDamage,
                        skillName = self.name,
                    })
                end
            end
        elseif discussion.color == "black" then
            for _, p in ipairs(targets) do
                if p:isWounded() and not p.dead and discussion.results[p.id].opinion == discussion.results[player.id].opinion then
                    room:recover({
                        who = p,
                        num = 1,
                        recoverBy = player,
                        skillName = self.name,
                    })
                end
            end
        end
    end,
}
caorui:addSkill(yiqing)
local yijing = fk.CreateTriggerSkill{
    name = "ysch4_yijing$",
    events = {fk.Damage},
    anim_type = "control",
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and ((target == player and #table.filter(data.to:getCardIds("h"),function (id)
            local card = Fk:getCardById(id)
            return card:getMark("@@ShownCards-inhand") == 0
        end) > 0) or (data.to == player and #table.filter(target:getCardIds("h"),function (id)
            local card = Fk:getCardById(id)
            return card:getMark("@@ShownCards-inhand") == 0
        end) > 0))
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tp = data.to
        local cards = table.filter(data.to:getCardIds("h"), function (id)
            local card = Fk:getCardById(id)
            return card:getMark("@@ShownCards-inhand") == 0
        end)
        if data.to == player then
            tp = target
            cards = table.filter(target:getCardIds("h"), function (id)
                local card = Fk:getCardById(id)
                return card:getMark("@@ShownCards-inhand") == 0
            end)
        end
        if #cards > 0 then
            local card = room:askForCard(tp, 1, 1, false, self.name, false, tostring(Exppattern{ id = cards }),
            "#ysch4_yijing-show")
            room:setCardMark(Fk:getCardById(card[1]), "@@ShownCards-inhand", 1)
            room:setCardMark(Fk:getCardById(card[1]), "@@ysch4_yijing-inhand-round", 1)
        end
    end,
}
local yijing_prohibit = fk.CreateProhibitSkill{
    name = "#ysch4_yijing_prohibit",
    prohibit_use = function(self, player, card)
        local cards = card:isVirtual() and card.subcards or {card.id}
        return table.find(cards, function(id)
            return Fk:getCardById(id):getMark("@@ysch4_yijing-inhand-round") > 0
        end)
    end,
    prohibit_discard = function (self, player, card)
        return card:getMark("@@ysch4_yijing-inhand-round") > 0
    end,
}
yijing:addRelatedSkill(yijing_prohibit)
caorui:addSkill(yijing)
Fk:loadTranslationTable{
    ["ysch4_yihe"] = "奕和",
    [":ysch4_yihe"] = "每回合结束时或你回复体力后，你可以令本轮对你造成伤害的角色弃置共计五张牌或本轮受到过伤害的角色摸共计三张牌。",
    ["@[player]ysch4_yihe_damage-round"] = "本轮造伤",
    ["@[player]ysch4_yihe_damaged-round"] = "本轮受伤",
    ["#ysch4_yihe-invoke"] = "是否发动 奕和？",
    ["#ysch4_yihe1"] = "弃牌",
    [":#ysch4_yihe1"] = "令本轮对你造成伤害的角色弃置共计五张牌",
    ["#ysch4_yihe_discard"] = "奕和：弃置至多 %arg 张牌",
    ["#ysch4_yihe_discardMax"] = "奕和：弃置 %arg 张牌",
    ["#ysch4_yihe2"] = "摸牌",
    [":#ysch4_yihe2"] = "令本轮受到过伤害的角色摸共计三张牌",
    ["ysch4_yihe_draw0"] = "摸零张牌",
    ["ysch4_yihe_draw1"] = "摸一张牌",
    ["ysch4_yihe_draw2"] = "摸两张牌",
    ["ysch4_yihe_draw3"] = "摸三张牌",
    ["#ysch4_yihe_draw"] = "奕和：摸至多 %arg 张牌",
    ["ysch4_yiqing"] = "议青",
    [":ysch4_yiqing"] = "轮次结束时，你可以与“奕和”上一次的目标议事，结果：红，意见不同角色各受到1点伤害；反之，意见相同角色各回复1点体力。",
    ["ysch4_yijing"] = "熠景",
    [":ysch4_yijing"] = "主公技，锁定技，对你造成伤害或受到你伤害的角色需明置一张手牌，且本轮不可使用或弃置之。",
    ["#ysch4_yijing-show"] = "熠景：明置一张手牌",
    ["@@ysch4_yijing-inhand-round"] = "熠景",
}
local dengsui = General:new(extension, "ysch4__dengsui", "han", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__dengsui"] = "邓绥",
    ["#ysch4__dengsui"] = "长秋的垂帘影",
    ["designer:ysch4__dengsui"] = "铝",
    ["cv:ysch4__dengsui"] = "佚名",
    ["illustrator:ysch4__dengsui"] = "未知",
}
Fk:addQmlMark{
    name = "yongyi",
    how_to_show = function(_, value, player)
        local num = 9
        for _, skill in ipairs(player:getAllSkills()) do
            if skill:isPlayerSkill(player) and not skill.name:startsWith("#") then
                num = num - player:usedSkillTimes(skill.name,Player.HistoryRound)
            end
        end
        return tostring(math.max(num,0))
    end,
    qml_path = function(name, value, p)
        if Self:isBuddy(p) or not string.startsWith(name, "@[yongyi]$") then
            return "packages/utility/qml/PlayerBox"
        end
        return ""
    end,
}
local yongyi = fk.CreateTriggerSkill{
    name = "ysch4_yongyi",
    frequency = Skill.Limited,
    anim_type = "big",
    events = {fk.RoundStart},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local tos = room:askForChoosePlayers(player,table.map(room.alive_players,Util.IdMapper),1,1,"#ysch4_yongyi-invoke",self.name)
        if #tos > 0 then
            self.cost_data = tos[1]
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = room:getPlayerById(self.cost_data)
        local choices = {}
        if #player:getCardIds("he") >= 3 then
            table.insert(choices,"#ysch4_yongyi1")
        end
        table.insert(choices,"#ysch4_yongyi2")
        local choice = room:askForChoice(to,choices,self.name,"#ysch4_yongyi-choice::"..player.id,true,{"#ysch4_yongyi1","#ysch4_yongyi2"})
        if choice == "#ysch4_yongyi1" then
            local skills = {}
            for _, skill in ipairs(to:getAllSkills()) do
                if skill:isPlayerSkill(to) and not skill.name:startsWith("#") then
                    room:invalidateSkill(to, skill.name, "-round")
                end
            end
            local cards = room:askForCardsChosen(to, player, 3, 3, "he", self.name, "#ysch4_yongyi-discard::"..player.id)
            room:throwCard(cards, self.name, player, to)
        else
            local mark = to:getTableMark("@[yongyi]ysch4_yongyi-round")
            table.insertIfNeed(mark,player.id)
            room:setPlayerMark(to,"@[yongyi]ysch4_yongyi-round",mark)
        end
    end,

    refresh_events = {fk.AfterSkillEffect},
    can_refresh = function (self, event, target, player, data)
        if target and target:hasSkill(data) and data.visible and type(target:getMark("@[yongyi]ysch4_yongyi-round")) == "table" and table.contains(target:getMark("@[yongyi]ysch4_yongyi-round"),player.id) then
            local num = 9
            for _, skill in ipairs(target:getAllSkills()) do
                if skill:isPlayerSkill(target) and not skill.name:startsWith("#") then
                    num = num - target:usedSkillTimes(skill.name,Player.HistoryRound)
                end
            end
            return num >= 0
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local choices = {"ysch4_yongyi_draw"}
        if table.find(player.room.alive_players, function(p)
            return target:canMoveCardsInBoardTo(p, nil)
        end) then
            table.insert(choices, "ysch4_yongyi_move::"..target.id)
        end
        local choice = room:askForChoice(player, choices, self.name, nil, false)
        if choice == "ysch4_yongyi_draw" then
            player:drawCards(1,self.name)
        else
            local targets = table.map(table.filter(player.room.alive_players, function(p)
                return target:canMoveCardsInBoardTo(p, nil)
            end), Util.IdMapper)
            if #targets > 0 then
                local to = room:askForChoosePlayers(player, targets, 1, 1, "#ysch4_yongyi-ask:" .. target.id, self.name, false)
                if #to > 0 then
                    room:askForMoveCardInBoard(player, target, room:getPlayerById(to[1]), self.name, nil, target)
                end
            end
        end
    end,
}
dengsui:addSkill(yongyi)
local linchao = fk.CreateTriggerSkill{
    name = "ysch4_linchao",
    events = {fk.EventPhaseEnd},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and target.seat == 1 and target.phase == Player.Play
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if room:askForSkillInvoke(target,self.name,nil,"#ysch4_linchao") then
            self.cost_data = target.id
            return true
        end
        if target.id ~= player.id then
            if room:askForSkillInvoke(player,self.name,nil,"#ysch4_linchao") then
                self.cost_data = player.id
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tos = {}
        table.insertIfNeed(tos,player.id)
        table.insertIfNeed(tos,target.id)
        for _, id in ipairs(tos) do
            local cp = room:getPlayerById(id)
            for _, skill in ipairs(cp:getAllSkills()) do
                if skill:isPlayerSkill(cp) then
                    if cp:usedSkillTimes(skill.name,Player.HistoryGame) > 0 then
                        cp:setSkillUseHistory(skill.name,0,Player.HistoryGame)
                    end
                    if cp:usedSkillTimes(skill.name,Player.HistoryRound) > 0 then
                        cp:setSkillUseHistory(skill.name,0,Player.HistoryRound)
                    end
                    if cp:usedSkillTimes(skill.name,Player.HistoryTurn) > 0 then
                        cp:setSkillUseHistory(skill.name,0,Player.HistoryTurn)
                    end
                    if cp:usedSkillTimes(skill.name,Player.HistoryPhase) > 0 then
                        cp:setSkillUseHistory(skill.name,0,Player.HistoryPhase)
                    end
                    room:validateSkill(cp, skill.name, "-round")
                    room:validateSkill(cp, skill.name, "-turn")
                    room:validateSkill(cp, skill.name, "-phase")
                end
            end
        end
        local tp = room:getPlayerById(self.cost_data)
        if not tp:isNude() then
            room:askForDiscard(tp,1,1,true,self.name,false,".","#ysch4_linchao-discard")
        end
    end,
}
dengsui:addSkill(linchao)
local youying = fk.CreateTriggerSkill{
    name = "ysch4_youyin",
    frequency = Skill.Wake,
    anim_type = "big",
    events = {fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryGame) == 0
    end,
    can_wake = function (self, event, target, player, data)
        return target.seat == 1
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local targets,tos,death = {},{},{}
        for index, cp in ipairs(room.players) do
            table.insert(tos,cp.id)
            if cp.dead then
                table.insert(death,cp.id)
            end
        end
        local shiftRemainingElements = function(arr, excluded_indices)
            local positions = {}
            -- 收集未被排除的索引
            for index, value in ipairs(arr) do
                if not table.contains(excluded_indices,value) then
                    table.insert(positions, index)
                end
            end
        
            -- 收集对应的值
            local values = {}
            for _, pos in ipairs(positions) do
                table.insert(values, arr[pos])
            end
        
            -- 循环左移一位
            local shifted_values = {}
            if #values > 0 then
                shifted_values = {table.unpack(values, 2)}
                table.insert(shifted_values, values[1])
            end
        
            -- 更新原数组
            for i, pos in ipairs(positions) do
                arr[pos] = shifted_values[i]
            end
        
            return arr
        end
        local new_tos = shiftRemainingElements(tos,death)
        for _, id in ipairs(new_tos) do
            table.insert(targets,room:getPlayerById(id))
        end

        room.players = targets
        room:arrangeSeats()
    end,
}
dengsui:addSkill(youying)
Fk:loadTranslationTable{
    ["ysch4_yongyi"] = "雍仪",
    [":ysch4_yongyi"] = "限定技，轮次开始时，你可令一名角色选择一项：1.弃置你三张牌，其所有技能本轮失效；2.本轮其前九次发动技能后，你可以摸一张牌或移动其场上一张牌。",
    ["#ysch4_yongyi-invoke"] = "是否发动 雍仪？令一名角色选择一项",
    ["#ysch4_yongyi-choice"] = "%dest对你发动了 雍仪，请选择一项",
    ["#ysch4_yongyi1"] = "技能失效",
    [":#ysch4_yongyi1"] = "弃置其三张牌，你所有技能本轮失效。",
    ["#ysch4_yongyi2"] = "对方增益",
    [":#ysch4_yongyi2"] = "本轮你前九次发动技能时，其可以摸一张牌或移动你场上一张牌。",
    ["#ysch4_yongyi-discard"] = "弃置 %dest 三张牌",
    ["@[yongyi]ysch4_yongyi-round"] = "被雍仪",
    ["ysch4_yongyi_draw"] = "摸一张牌",
    ["ysch4_yongyi_move"] = "移动%dest场上一张牌",
    ["#ysch4_yongyi-ask"] = "震袭：选择要将 %src 场上的牌移动给的角色",
    ["ysch4_linchao"] = "临朝",
    [":ysch4_linchao"] = "一号位的出牌阶段结束时，其或你可以重置你与其的技能，然后弃置一张牌。",
    ["#ysch4_linchao"] = "临朝：你可以重置邓绥与你的所有技能，然后弃置一张牌",
    ["#ysch4_linchao-discard"] = "临朝：弃置一张牌",
    ["ysch4_youyin"] = "忧隐",
    [":ysch4_youyin"] = "觉醒技，一号位的回合结束时，存活角色座次号顺时针移动一位。",
}
local donk = General:new(extension, "ysch4__donk", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__donk"] = "‮p o u ʞ‬",
    ["#ysch4__donk"] = "无人之境",
    ["designer:ysch4__donk"] = "伶",
    ["cv:ysch4__donk"] = "佚名",
    ["illustrator:ysch4__donk"] = "未知",
}
if not Fk.skills["wushuang"] then
    local wushuang = fk.CreateTriggerSkill{
        name = "wushuang",
        anim_type = "offensive",
        frequency = Skill.Compulsory,
        events = {fk.TargetSpecified, fk.TargetConfirmed},
        can_trigger = function(self, event, target, player, data)
          if not player:hasSkill(self) then
            return false
          end
      
          if event == fk.TargetSpecified then
            return target == player and table.contains({ "slash", "duel" }, data.card.trueName)
          else
            return data.to == player.id and data.card.trueName == "duel"
          end
        end,
        on_use = function(self, event, target, player, data)
          data.fixedResponseTimes = data.fixedResponseTimes or {}
          if data.card.trueName == "slash" then
            data.fixedResponseTimes["jink"] = 2
          else
            data.fixedResponseTimes["slash"] = 2
            data.fixedAddTimesResponsors = data.fixedAddTimesResponsors or {}
            table.insert(data.fixedAddTimesResponsors, (event == fk.TargetSpecified and data.to or data.from))
          end
        end,
    }
    Fk:addSkill(wushuang)
    Fk:loadTranslationTable{
        ["wushuang"] = "无双",
        [":wushuang"] = "锁定技，当你使用【杀】指定目标后，其使用【闪】抵消此【杀】的方式改为需连续使用两张【闪】；当你使用【决斗】指定目标后，或当你成为【决斗】的目标后，你令其打出【杀】响应此【决斗】的方式改为需连续打出两张【杀】。",
    }
end
if not Fk.skills["ol_ex__xuanfeng"] then
    local ol_ex__xuanfeng = fk.CreateTriggerSkill{
        name = "ol_ex__xuanfeng",
        anim_type = "control",
        events = {fk.AfterCardsMove},
        can_trigger = function(self, event, target, player, data)
          if player:hasSkill(self) then
            for _, move in ipairs(data) do
              if move.from == player.id then
                local n = 0
                for _, info in ipairs(move.moveInfo) do
                  if info.fromArea == Card.PlayerHand then
                    n = n + 1
                  elseif info.fromArea == Card.PlayerEquip then
                    n = 2
                  end
                end
                if n > 1 then
                  return table.find(player.room:getOtherPlayers(player, false), function(p) return not p:isNude() end)
                end
              end
            end
          end
        end,
        on_cost = function(self, event, target, player, data)
          local room = player.room
          local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
            return not p:isNude() end), Util.IdMapper)
          while player.room:askForSkillInvoke(player, self.name) do
            local to = room:askForChoosePlayers(player, targets, 1, 1, "#xuanfeng-choose", self.name, true)
            if #to > 0 then
              self.cost_data = to[1]
              return true
            end
          end
        end,
        on_use = function(self, event, target, player, data)
          local room = player.room
          local to = room:getPlayerById(self.cost_data)
          local card = room:askForCardChosen(player, to, "he", self.name)
          room:throwCard({card}, self.name, to, player)
          local targets = table.map(table.filter(room:getOtherPlayers(player, false), function(p)
            return not p:isNude() end), Util.IdMapper)
          if #targets == 0 or player.dead then return end
          to = room:askForChoosePlayers(player, targets, 1, 1, "#xuanfeng-choose", self.name, true)
          if #to > 0 then
            to = room:getPlayerById(to[1])
            card = room:askForCardChosen(player, to, "he", self.name)
            room:throwCard({card}, self.name, to, player)
          end
        end,
    }
    Fk:addSkill(ol_ex__xuanfeng)
    Fk:loadTranslationTable{
        ["ol_ex__xuanfeng"] = "旋风",
        [":ol_ex__xuanfeng"] = "当你失去装备区里的牌后，或一次性失去至少两张牌后，你可以依次弃置至多两名其他角色共计至多两张牌。",

        ["#xuanfeng-choose"] = "旋风：你可以弃置一名角色的一张牌",
    }
end
if not Fk.skills["lianpo"] then
    local lianpo = fk.CreateTriggerSkill{
        name = "lianpo",
        anim_type = "offensive",
        events = {fk.TurnEnd},
        can_trigger = function(self, event, target, player, data)
          if player:hasSkill(self) then
            local room = player.room
            local events = room.logic:getEventsOfScope(GameEvent.Death, 999, function(e)
              local deathStruct = e.data[1]
              return deathStruct.damage and deathStruct.damage.from and deathStruct.damage.from == player
            end, Player.HistoryTurn)
            return #events > 0
          end
        end,
        on_cost = function(self, event, target, player, data)
          return player.room:askForSkillInvoke(player, self.name, nil, "#lianpo-invoke")
        end,
        on_use = function(self, event, target, player, data)
          player:gainAnExtraTurn(true)
        end,
    }
    Fk:addSkill(lianpo)
    Fk:loadTranslationTable{
        ["lianpo"] = "连破",
        [":lianpo"] = "当你杀死一名角色后，你可于此回合结束后获得一个额外回合。",
    }
end
if not Fk.skills["jiaozi"] then
    local jiaozi = fk.CreateTriggerSkill{
        name = "jiaozi",
        anim_type = "offensive",
        events = {fk.DamageCaused, fk.DamageInflicted},
        frequency = Skill.Compulsory,
        can_trigger = function(self, event, target, player, data)
          return target == player and player:hasSkill(self) and
            table.every(player.room:getOtherPlayers(player, false), function(p)
              return player:getHandcardNum() > p:getHandcardNum() end)
        end,
        on_use = function(self, event, target, player, data)
          data.damage = data.damage + 1
        end,
    }
    Fk:addSkill(jiaozi)
    Fk:loadTranslationTable{
        ["jiaozi"] = "骄恣",
        [":jiaozi"] = "锁定技，当你造成或受到伤害时，若你的手牌为全场唯一最多，则此伤害+1。",
    }
end
if not Fk.skills["jiang"] then
    local jiang = fk.CreateTriggerSkill{
        name = "jiang",
        anim_type = "drawcard",
        events ={fk.TargetSpecified, fk.TargetConfirmed},
        can_trigger = function(self, event, target, player, data)
          return target == player and player:hasSkill(self) and 
            ((data.card.trueName == "slash" and data.card.color == Card.Red) or data.card.name == "duel") and
            (event == fk.TargetConfirmed or data.firstTarget)
        end,
        on_use = function(self, event, target, player, data)
          player:drawCards(1, self.name)
        end,
    }
    Fk:addSkill(jiang)
    Fk:loadTranslationTable{
        ["jiang"] = "激昂",
        [":jiang"] = "当你使用【决斗】或红色【杀】指定目标后，或成为【决斗】或红色【杀】的目标后，你可以摸一张牌。",
    }
end
local fuerjiaheniliuershang = fk.CreateTriggerSkill{
    name = "ysch4_fuerjiaheniliuershang",
    on_acquire = function (self, player, is_start)
        local room = player.room
        local skills = table.filter({"wushuang","ol_ex__xuanfeng","lianpo"},function (skill)
            return not player:hasSkill(skill)
        end)
        room:setPlayerMark(player,self.name,skills)
        room:handleAddLoseSkills(player,skills,nil,false,true)
    end,
    on_lose = function (self, player, is_death)
        local room = player.room
        local skills = player:getTableMark(self.name)
        room:setPlayerMark(player,self.name,0)
        room:handleAddLoseSkills(player,"-"..table.concat(skills,"|-"),nil,false,true)
    end,
}
donk:addSkill(fuerjiaheniliuershang)
local nianqingdewangyiqifengfa = fk.CreateTriggerSkill{
    name = "ysch4_nianqingdewangyiqifengfa",
    on_acquire = function (self, player, is_start)
        local room = player.room
        local skills = table.filter({"ex__yingzi","jiaozi","jiang"},function (skill)
            return not player:hasSkill(skill)
        end)
        room:setPlayerMark(player,self.name,skills)
        room:handleAddLoseSkills(player,skills,nil,false,true)
    end,
    on_lose = function (self, player, is_death)
        local room = player.room
        local skills = player:getTableMark(self.name)
        room:setPlayerMark(player,self.name,0)
        room:handleAddLoseSkills(player,"-"..table.concat(skills,"|-"),nil,false,true)
    end,
}
donk:addSkill(nianqingdewangyiqifengfa)
for loop = 1, 50, 1 do
    --if loop % 2 == 1 then
        local qianxun = fk.CreateProhibitSkill{
            name = "ysch4_bixiuke"..loop.."__qianxun",
            frequency = Skill.Compulsory,
            is_prohibited = function(self, from, to, card)
              if to:hasSkill(self) then
                return card.name == "indulgence" or card.name == "snatch"
              end
            end,
        }
        Fk:addSkill(qianxun)
        Fk:loadTranslationTable{
            ["ysch4_bixiuke"..loop.."__qianxun"] = "谦逊",
            [":ysch4_bixiuke"..loop.."__qianxun"] = "锁定技，你不能被选择为【顺手牵羊】与【乐不思蜀】的目标。",
        }
    --[[else
        local ex__qianxun = fk.CreateTriggerSkill{
            name = "ysch4_bixiuke"..loop.."__qianxun",
            events = {fk.CardEffecting},
            can_trigger = function(self, event, target, player, data)
              return player:hasSkill(self) and target == player and data.from ~= player.id and data.card.type == Card.TypeTrick and
              U.isOnlyTarget(player, data, event) and not player:isKongcheng()
            end,
            on_use = function(self, event, target, player, data)
              player:addToPile("$ex__qianxun", player:getCardIds("h"), false, self.name)
            end,
        }
        local ex__qianxun_delay = fk.CreateTriggerSkill{
            name = "#ysch4_bixiuke"..loop.."__qianxun_delay",
            mute = true,
            events = {fk.TurnEnd},
            can_trigger = function(self, event, target, player, data)
              return #player:getPile("$ex__qianxun") > 0
            end,
            on_cost = Util.TrueFunc,
            on_use = function(self, event, target, player, data)
              player.room:obtainCard(player.id, player:getPile("$ex__qianxun"), false)
            end,
        }
        ex__qianxun:addRelatedSkill(ex__qianxun_delay)
        Fk:addSkill(ex__qianxun)
        Fk:loadTranslationTable{
            ["$ex__qianxun"] = "谦逊",
            ["ysch4_bixiuke"..loop.."__qianxun"] = "谦逊",
            [":ysch4_bixiuke"..loop.."__qianxun"] = "当一张延时锦囊牌或其他角色使用的普通锦囊牌对你生效时，若你是此牌唯一目标，则你可以将所有手牌扣置于武将牌上，然后此回合结束时，你获得这些牌。",
        }
    end]]--
end
local tiancaibuxuyaozhiwu = fk.CreateTriggerSkill{
    name = "ysch4_bixiuke",
    events = {fk.Damage,fk.Damaged},
    switch_skill_name = "ysch4_bixiuke",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and target == player then
            if event == fk.Damage then
                if player:getSwitchSkillState(self.name) == fk.SwitchYin then
                    for _, skill in ipairs(player.player_skills) do
                        if skill:isPlayerSkill(player) and not skill.name:startsWith("#") and Fk:translate(skill.name,"zh_CN") == "谦逊" then
                            return true
                        end
                    end
                end
            else
                if player:getSwitchSkillState(self.name) == fk.SwitchYang then
                    local gskills = Fk.generals[player.general]:getSkillNameList()
                    if target.deputyGeneral and target.deputyGeneral ~= "" then
                        table.insertTableIfNeed(gskills, Fk.generals[player.deputyGeneral]:getSkillNameList())
                    end
                    for _, skill in ipairs(player.player_skills) do
                        if skill:isPlayerSkill(player) and not skill.name:startsWith("#") and not table.contains(gskills,skill.name) then
                            return true
                        end
                    end
                end
            end
        end
    end,
    frequency = Skill.Compulsory,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local choices = {}
        local prompt = "#ysch4_bixiuke-yang"
        if event == fk.Damage then
            prompt = "#ysch4_bixiuke-yin"
            for _, skill in ipairs(player.player_skills) do
                if skill:isPlayerSkill(player) and not skill.name:startsWith("#") and Fk:translate(skill.name,"zh_CN") == "谦逊" then
                    table.insertIfNeed(choices,skill.name)
                end
            end
        else
            local gskills = Fk.generals[player.general]:getSkillNameList()
            if target.deputyGeneral and target.deputyGeneral ~= "" then
                table.insertTableIfNeed(gskills, Fk.generals[player.deputyGeneral]:getSkillNameList())
            end
            for _, skill in ipairs(player.player_skills) do
                if skill:isPlayerSkill(player) and not skill.name:startsWith("#") and not table.contains(gskills,skill.name) then
                    table.insertIfNeed(choices,skill.name)
                end
            end
        end
        self.cost_data = room:askForChoice(player,choices,self.name,prompt,true)
        return true
    end,
    anim_type = "switch",
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:handleAddLoseSkills(player,"-"..self.cost_data)
        if event == fk.Damage then
            player:drawCards(2,self.name)
        else
            local skills = {}
            for i = 1, 50, 1 do
                local skill = "ysch4_bixiuke"..i.."__qianxun"
                if not player:hasSkill(skill) then
                    table.insert(skills,skill)
                end
            end
            room:handleAddLoseSkills(player,table.random(skills))
        end
    end,
}
donk:addSkill(tiancaibuxuyaozhiwu)
donk:addRelatedSkill("wushuang")
donk:addRelatedSkill("ol_ex__xuanfeng")
donk:addRelatedSkill("lianpo")
donk:addRelatedSkill("ex__yingzi")
donk:addRelatedSkill("jiaozi")
donk:addRelatedSkill("jiang")
donk:addRelatedSkill("ysch4_bixiuke1__qianxun")
--donk:addRelatedSkill("ysch4_bixiuke2__qianxun")
Fk:loadTranslationTable{
    ["ysch4_fuerjiaheniliuershang"] = "伏尔加河逆流而上",
    [":ysch4_fuerjiaheniliuershang"] = "锁定技，你视为拥有“无双”，“旋风”，“连破”。",
    ["ysch4_nianqingdewangyiqifengfa"] = "年轻的王意气风发",
    [":ysch4_nianqingdewangyiqifengfa"] = "锁定技，你视为拥有“英姿”，“骄恣”，“激昂”。",
    ["ysch4_bixiuke"] = "必修课",
    [":ysch4_bixiuke"] = "锁定技，转换技，①当你受到伤害后，你将一个衍生技变为“谦逊”。②当你造成伤害后，你失去一个“谦逊”并摸两张牌。"..
  "<br><br> <font color = '#a40000'>“我们一般不会用‘屠杀’去形容一位选手在世界级赛事上的表现，但很遗憾，这就是事实。”",
    ["#ysch4_bixiuke-yang"] = "必修课：将一个衍生技变为“谦逊”",
    ["#ysch4_bixiuke-yin"] = "必修课：失去一个“谦逊”并摸两张牌",
}
local Danking = General:new(extension, "ysch4__Danking", "god", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__Danking"] = "‮Бuᴉʞuɐꓷ‬",
    ["#ysch4__Danking"] = "",
    ["designer:ysch4__Danking"] = "铝",
    ["cv:ysch4__Danking"] = "佚名",
    ["illustrator:ysch4__Danking"] = "未知",
}
local bafanglaicai = fk.CreateTriggerSkill{
    name = "ysch4_bafanglaicai",
    events = {fk.AfterCardsMove},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self) then
            if table.find(data, function (move) return move.extra_data and move.extra_data.ysch4_bafanglaicai end) then
                local suits = {}
                for _, id in ipairs(player.room:getBanner("@$CenterArea") or Util.DummyTable) do
                    table.insertIfNeed(suits, Fk:getCardById(id).suit)
                end
                table.removeOne(suits, Card.NoSuit)
                return #suits == 4
            end
        end
    end,
    frequency = Skill.Compulsory,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local cards = Fk:currentRoom():getBanner("@$CenterArea")
        local num = #room.logic:getEventsOfScope(GameEvent.Phase, 999, function (e)
            return table.contains({Player.Start,Player.Judge,Player.Draw,Player.Play,Player.Discard,Player.Finish},e.data[2])
        end, Player.HistoryTurn)
        if num == 0 then return end
        if num < #cards then
            self.cost_data = room:askForCard(player,num,num,false,self.name,false,tostring(Exppattern{ id = cards }),"#ysch4_bafanglaicai:::"..num,cards)
        else
            self.cost_data = cards
        end
        return true
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local num = #room.logic:getEventsOfScope(GameEvent.Phase, 999, function (e)
            return table.contains({Player.Start,Player.Judge,Player.Draw,Player.Play,Player.Discard,Player.Finish},e.data[2])
        end, Player.HistoryTurn)
        RemoveCenterCards(player, self.cost_data)
        if #room:getBanner("@$CenterArea") == 0 and not player.dead then
            player:drawCards(num, self.name)
        end
    end,

    refresh_events = {fk.BeforeCardsMove},
    can_refresh = function (self, event, target, player, data)
        local suits = {}
        for _, id in ipairs(player.room:getBanner("@$CenterArea") or Util.DummyTable) do
            table.insertIfNeed(suits, Fk:getCardById(id).suit)
        end
        table.removeOne(suits, Card.NoSuit)
        return #suits < 4
    end,
    on_refresh = function (self, event, target, player, data)
        for _, move in ipairs(data) do
            if move.toArea == Card.DiscardPile then
                move.extra_data = move.extra_data or {}
                move.extra_data.ysch4_bafanglaicai = true
            end
        end
    end,
}
bafanglaicai.CenterArea = true
Danking:addSkill(bafanglaicai)
Fk:addQmlMark{
    name = "ysch4_shunjingjinghong",
    qml_path = function(name, value, p)
      if Self == p then
        return "packages/ysch_Al/qml/ysch4_shunjingjinghong"
      end
      return ""
    end,
    how_to_show = function(name, value, p)
      return " "
    end,
}
local shunjingjinghong = fk.CreateTriggerSkill{
    name = "ysch4_shunjingjinghong",
    events = {fk.PreCardUse},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and target == player and (data.extra_data or {}).ysch4_shunjingjinghong_cards then
            for _, id in ipairs(Card:getIdList(data.card)) do
                local card = Fk:getCardById(id)
                if card.trueName == "slash" and table.contains(data.extra_data.ysch4_shunjingjinghong_cards,id) then
                    return true
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local ids = {}
        for index, id in ipairs(data.extra_data.ysch4_shunjingjinghong_cards) do
            local card = Fk:getCardById(id)
            if card.trueName == "slash" and table.contains(Card:getIdList(data.card),id) then
                if index > 1 then
                    table.insertIfNeed(ids,data.extra_data.ysch4_shunjingjinghong_cards[index-1])
                end
                if index < #data.extra_data.ysch4_shunjingjinghong_cards then
                    table.insertIfNeed(ids,data.extra_data.ysch4_shunjingjinghong_cards[index+1])
                end
            end
        end
        if #ids > 0 then
            self.cost_data = ids
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local ids = Card:getIdList(data.card)
        table.insertTableIfNeed(ids,self.cost_data)

        local _card = Fk:cloneCard(data.card.name)
        _card:addSubcards(ids)
        --[[room:moveCards({
            from = player.id,
            ids = self.cost_data,
            toArea = Card.DiscardPile,
            moveReason = fk.ReasonPutIntoDiscardPile,
            skillName = self.name,
        })]]--
        --[[room:sendLog{
            type = "#FilterCard",
            from = player.id,
            arg = self.name,
            arg2 = data.card:toLogString(),
            arg3 = _card:toLogString(),
        }]]--
        data.card = _card
        data.additionalDamage = (data.additionalDamage or 0) + 1

        if data.tos and #data.tos > 0 then
            data.disresponsiveList = data.disresponsiveList or {}
            for _, cp in ipairs(data.tos) do
                local to = room:getPlayerById(cp[1])
                local nums = table.map(ids,function (cardId)
                    local card = Fk:getCardById(cardId,true)
                    return tostring(card.number)
                end)
                local cards = table.filter(to:getCardIds("he"),function (cardId)
                    local card = Fk:getCardById(cardId,true)
                    return table.contains(nums,tostring(card.number)) and not player:prohibitDiscard(card)
                end)
                if #cards > 0 and room:askForSkillInvoke(to,self.name,nil,"#ysch4_shunjingjinghong-discard:::"..table.concat(nums,"、")..":"..data.card:toLogString()) then
                    room:throwCard(cards, self.name, to, to)
                else
                    table.insertIfNeed(data.disresponsiveList, to.id)
                end
            end
        end
    end,

    refresh_events = {fk.PreCardUse},
    can_refresh = function (self, event, target, player, data)
        return target == player and player:hasSkill(self.name)
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local handcards = player:getCardIds("h")
        data.extra_data = data.extra_data or {}
        data.extra_data.ysch4_shunjingjinghong_cards = handcards
    end,

    on_acquire = function (self, player, is_start)
        local room = player.room
        room:setPlayerMark(player, "@[ysch4_shunjingjinghong]", { value = player.id })
        room:setPlayerMark(player, MarkEnum.SortProhibited, 1)
    end,
    on_lose =function (self, player, is_death)
        local room = player.room
        room:setPlayerMark(player, "@[ysch4_shunjingjinghong]", 0)
        room:setPlayerMark(player, MarkEnum.SortProhibited, 0)
    end,
}
Danking:addSkill(shunjingjinghong)
local Danking_win_audio = fk.CreateTriggerSkill{name = "ysch4__Danking_win_audio",}
Danking_win_audio.package = extension
Fk:addSkill(Danking_win_audio)
Fk:loadTranslationTable{
    ["ysch4_bafanglaicai"] = "八方来财",
    [":ysch4_bafanglaicai"] = "锁定技，中央区花色补全后，你移去其中X张牌。若中央区因此清空，你摸X张牌（X为本回合所有角色已执行阶段数，不足则全弃）。",
    ["#ysch4_bafanglaicai"] = "八方来财：移去中央区的 %arg 张牌",
    ["ysch4_shunjingjinghong"] = "瞬镜惊鸿",
    [":ysch4_shunjingjinghong"] = "你不能调整手牌。你使用手中的【杀】时，将与之相邻牌加入底牌令之伤害+1；除非目标弃置底牌包含的点数，否则无法响应此牌。",
    ["@[ysch4_shunjingjinghong]"] = "瞬镜惊鸿",
    ["#ysch4_shunjingjinghong-discard"] = "瞬镜惊鸿：是否弃置以下点数的牌（%arg）？否则你不能响应%arg2",

    ["$ysch4_bafanglaicai1"] = "感谢老板的魔法书，别再送了别再送了兄弟们。",
    ["$ysch4_bafanglaicai2"] = "我说实话我想学习，我真的有点想学习。也没有支持我的给我送本魔法书，帮我凑一下学费。",
    ["$ysch4_shunjingjinghong1"] = "欸！百里守约~",
    ["$ysch4_shunjingjinghong2"] = "马可波罗！",
    ["ysch4__Danking_win_audio"] = "胜利语音",
    ["$ysch4__Danking_win_audio"] = "我能打上海major，我能打上海major，全场高呼Danking!Danking!",
    ["~ysch4__Danking"] = "肚子疼肚子疼！我下播了啊真不行了。",
}
local liuyu = General:new(extension, "ysch4__liuyu", "jin", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__liuyu"] = "刘裕",
    ["#ysch4__liuyu"] = "长刀遏血",
    ["designer:ysch4__liuyu"] = "胖即是胖",
    ["cv:ysch4__liuyu"] = "佚名",
    ["illustrator:ysch4__liuyu"] = "未知",
}
local zhanli = fk.CreateTriggerSkill{
    name = "ysch4_zhanli",
    anim_type = "drawcard",
    events = {fk.BeforeDrawCard},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self) and target == player
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        data.num = data.num + 2
        local drawEvent = room.logic:getCurrentEvent().parent
        if data.skillName == "recast" then
            drawEvent = room.logic:getCurrentEvent()
        end
        drawEvent:addCleaner(function ()
            local num = player:getHandcardNum() // 2
            local cards = player.room:askForCard(player, num, num, false, self.name, false, nil, "#ysch4_zhanli-card")
            room:showCards(cards,player)
            for _, id in ipairs(cards) do
                room:setCardMark(Fk:getCardById(id), "@@ysch4_zhanli-turn-inhand", 1)
            end
        end)
    end,
    dynamic_desc = function (self, player, lang)
        if Fk:currentRoom():isGameMode("1v2_mode") or Fk:currentRoom():isGameMode("hell_combat_mode") then
            return "当你摸牌时，你可以多摸两张牌，然后你展示至少半数手牌，这些牌均视为无次数限制的【杀】直到本回合结束。"
        end
        return "当你摸牌时，你可以多摸两张牌，然后你展示至少半数手牌，这些牌均视为【杀】直到本回合结束。"
    end,
}
local zhanli_filter = fk.CreateFilterSkill{
    name = "#ysch4_zhanli_filter",
    anim_type = "offensive",
    card_filter = function(self, card, player)
        return card:getMark("@@ysch4_zhanli-turn-inhand") > 0 and table.contains(player:getCardIds("h"), card.id)
    end,
    view_as = function(self, card)
        local c = Fk:cloneCard("slash", card.suit, card.number)
        c.skillName = "ysch4_zhanli"
        return c
    end,
}
zhanli:addRelatedSkill(zhanli_filter)
local zhanli_target = fk.CreateTargetModSkill{
    name = "#ysch4_zhanli_target",
    bypass_times = function(self, player, skill, scope, card)
        return (Fk:currentRoom():isGameMode("1v2_mode") or Fk:currentRoom():isGameMode("hell_combat_mode")) and card and table.contains(card.skillNames, zhanli.name)
    end,
}
zhanli:addRelatedSkill(zhanli_target)
liuyu:addSkill(zhanli)
local aofen = fk.CreateTriggerSkill{
    name = "ysch4_aofen",
    anim_type = "offensive",
    events = {fk.AfterCardTargetDeclared},
    can_trigger = function (self, event, target, player, data)
        return target == player and player:hasSkill(self) and
        data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[self.name]
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        self.cost_data = room:askForChoice(player,{"#ysch4_aofen1","#ysch4_aofen2:::"..tostring(player:usedSkillTimes(self.name,Player.HistoryTurn)+1),"#ysch4_aofen3"},self.name,"#ysch4_aofen-prompt")
        return true
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        player:addCardUseHistory("slash", -1)
        local index = string.sub(self.cost_data,13,13)
        if index == "3" then
            player:showCards(player.player_cards[Player.Hand])
            local ids = {}
            for _, id in ipairs(player.player_cards[Player.Hand]) do
                if Fk:getCardById(id,false).trueName ~= "slash" then
                    table.insert(ids, id)
                end
            end
            if #ids > 0 then
                room:throwCard(ids, self.name, player, player)
            end
        end
        if index ~= "2" then
            local card_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
            if card_event then
                card_event.ysch4_aofen_draw = card_event.ysch4_aofen_draw or {}
                table.insert(card_event.ysch4_aofen_draw,player.id)
            end
        end
        if index ~= "1" then
            local targets = room:getUseExtraTargets(data)
            local num = player:usedSkillTimes(self.name,Player.HistoryTurn)
            if #targets > 0 then
                local tos = room:askForChoosePlayers(player, targets, 1, num,
                "#ysch4_aofen-choose:::"..data.card:toLogString()..":"..num, self.name, true)
                if #tos > 0 then
                    table.forEach(tos, function (id)
                        table.insert(data.tos, {id})
                    end)
                end
            end
        end
    end,

    refresh_events = {fk.AfterCardUseDeclared,fk.Damage},
    can_refresh = function (self, event, target, player, data)
        if event == fk.Damage then
            local card_event = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
            return card_event and card_event.ysch4_aofen_draw and table.contains(card_event.ysch4_aofen_draw, player.id) and data.card == card_event.data[1].card
        else
            return target == player and player:hasSkill(self, true)
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        if event == fk.Damage then
            player:drawCards(1, self.name)
        else
            local mark = player:getMark("@[chara]ysch4_aofen")
            if mark == 0 and target == player then
                if data.tos and #data.tos == 1 then
                    room:setPlayerMark(player,"@[chara]ysch4_aofen",TargetGroup:getRealTargets(data.tos)[1])
                end
            else
                room:setPlayerMark(player,"@[chara]ysch4_aofen",0)
                if data.card.trueName == "slash" and data.tos and TargetGroup:getRealTargets(data.tos)[1] == mark then
                    room:setPlayerMark(player,"@[chara]ysch4_aofen",0)
                    data.extra_data = data.extra_data or {}
                    data.extra_data.combo_skill = data.extra_data.combo_skill or {}
                    data.extra_data.combo_skill[self.name] = true
                    --[[data.extra_data.ysch4_aofen = data.extra_data.ysch4_aofen or {}
                    table.insert(data.extra_data.ysch4_aofen,player.id)]]--
                end
            end
        end
    end,
}
liuyu:addSkill(aofen)
Fk:loadTranslationTable{
    ["ysch4_zhanli"] = "战厉",
    [":ysch4_zhanli"] = "当你摸牌时，你可以多摸两张牌，然后你展示至少半数手牌，这些牌均视为【杀】直到本回合结束。",
    ["#ysch4_zhanli-card"] = "战厉：展示半数手牌，这些牌本回合视为【杀】",
    ["@@ysch4_zhanli-turn-inhand"] = "战厉",
    ["#ysch4_zhanli_filter"] = "战厉",
    ["ysch4_aofen"] = "鏖奋",
    [":ysch4_aofen"] = "连招技（指定唯一目标的牌＋指定此目标角色为目标的【杀】），此【杀】不计入次数且你可以选择一项：此【杀】造成伤害后你摸一张牌；令至多X名角色也成为此【杀】的目标（X为此技能本回合发动次数）。背水：展示所有手牌并弃置其中所有不为【杀】的牌。",
    ["@[chara]ysch4_aofen"] = "鏖奋",
    ["#ysch4_aofen-prompt"] = "",
    ["#ysch4_aofen1"] = "此【杀】造成伤害后你摸一张牌",
    ["#ysch4_aofen2"] = "令至多 %arg 名角色也成为此【杀】的目标",
    ["#ysch4_aofen3"] = "背水：展示所有手牌并弃置其中所有不为【杀】的牌",
    ["#ysch4_aofen-choose"] = "鏖奋：请为此【%arg】额外指定至多 %arg2 个目标",
}
local yiyanqing = General:new(extension, "ysch4__yiyanqing", "houzhou", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["houzhou"] = "后周",
    ["ysch4__yiyanqing"] = "易延庆",
    ["#ysch4__yiyanqing"] = "不匮孝思",
    ["designer:ysch4__yiyanqing"] = "易大剧",
    ["cv:ysch4__yiyanqing"] = "佚名",
    ["illustrator:ysch4__yiyanqing"] = "未知",
}
Fk:addPoxiMethod{
    name = "ysch4_shouzhi",
    prompt = function (data, extra_data)
        return "#ysch4_shouzhi-card"
    end,
    card_filter = function (to_select, selected, data, extra_data)
        if data and #selected < #data then
            for _, id in ipairs(selected) do
                for _, v in ipairs(data) do
                    if table.contains(v[2], id) and table.contains(v[2], to_select) then
                        return false
                    end
                end
            end
            return true
        end
    end,
    feasible = function(selected, data)
        return data and #data == #selected
    end,
    default_choice = function(data)
        if not data then return {} end
        local cids = table.map(data, function(v) return v[2][1] end)
        return cids
    end,
}
local shouzhi = fk.CreateTriggerSkill{
    name = "ysch4_shouzhi",
    anim_type = "drawcard",
    events = {fk.BeforeDrawCard,fk.AfterCardsMove},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self) then
            if event == fk.BeforeDrawCard then
                return target == player
            else
                local suits = {}
                for _, id in ipairs(player:getPile("$ysch4_gen")) do
                    table.insertIfNeed(suits, Fk:getCardById(id).suit)
                end
                if #suits == 4 then
                    for _, move in ipairs(data) do
                        if move.to == player.id and move.toArea == Card.PlayerSpecial then
                            return true
                        end
                    end
                end
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        if event == fk.BeforeDrawCard then
            if room:askForSkillInvoke(player,self.name,nil,"#ysch4_shouzhi-prompt") then
                return true
            end
        else
            local cardsMap = {}
            for _, id in ipairs(player:getPile("$ysch4_gen")) do
                local suit = Fk:getCardById(id):getSuitString(true)
                cardsMap[suit] = cardsMap[suit] or {}
                table.insert(cardsMap[suit], id)
            end
            local card_data = {}
            for suit, ids in pairs(cardsMap) do
                table.insertIfNeed(card_data, {suit,ids})
            end
            if #card_data == 0 then return end
            local result = room:askForPoxi(player, "ysch4_shouzhi", card_data, nil, false)
            self.cost_data = result
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        if event == fk.BeforeDrawCard then
            data.num = data.num - 1
            local drawEvent = room.logic:getCurrentEvent().parent
            if data.skillName == "recast" then
                drawEvent = room.logic:getCurrentEvent()
            end
            drawEvent:addCleaner(function ()
                player:addToPile("$ysch4_gen", room:getNCards(2), true, self.name)
            end)
        else
            local cards = {}
            for _, id in ipairs(player:getPile("$ysch4_gen")) do
                if not table.contains(self.cost_data,id) then
                    table.insertIfNeed(cards,id)
                end
            end
            room:obtainCard(player, cards, true, fk.ReasonJustMove, player.id, self.name)
            room:moveCardTo(self.cost_data, Card.Processing, nil, fk.ReasonJustMove, self.name, "$ysch4_gen")
            player:addToPile("$ysch4_zhi", self.cost_data, true, self.name)
        end
    end,
}
yiyanqing:addSkill(shouzhi)
local lianli = fk.CreateActiveSkill{
    name = "ysch4_lianli",
    switch_skill_name = "ysch4_lianli",
    expand_pile = function (self, player)
        if player:getSwitchSkillState(self.name) == fk.SwitchYang then
            return "$ysch4_gen"
        else
            return "$ysch4_zhi"
        end
    end,
    can_use = function (self, player, card, extra_data)
        if player:getSwitchSkillState(self.name) == fk.SwitchYang then
            return #player:getPile("$ysch4_gen") > 0 and player:getHandcardNum() > 0
        else
            return #player:getPile("$ysch4_zhi") > 0 and player:getHandcardNum() > 0
        end
    end,
    card_num = 2,
    prompt = function (self, selected_cards, selected_targets)
        if Self:getSwitchSkillState(self.name) == fk.SwitchYang then
            return "#ysch4_lianli_yang"
        else
            return "#ysch4_lianli_yin"
        end
    end,
    card_filter = function (self, to_select, selected, player)
        if #selected == 2 or Fk:currentRoom():getCardArea(to_select) == Player.Equip then return false end
        if player:getSwitchSkillState(self.name) == fk.SwitchYin and table.contains(player:getPile("$ysch4_zhi"),to_select) then
            local card = Fk:cloneCard(Fk:getCardById(to_select).name)
            if player:prohibitUse(card) or not player:canUse(card)
            or not table.find(Fk:currentRoom().alive_players, function (p)
              return not player:isProhibited(p, card) and card.skill:modTargetFilter(p.id, {}, player, card, true)
            end) or card.type == Card.TypeEquip then
                return false
            end
        end
        if #selected > 0 then
            local id = selected[1]
            if table.contains(player.player_cards[Player.Hand],id) then
                if player:getSwitchSkillState(self.name) == fk.SwitchYang then
                    return table.contains(player:getPile("$ysch4_gen"),to_select) and Fk:getCardById(to_select).type == Fk:getCardById(id).type
                else
                    return table.contains(player:getPile("$ysch4_zhi"),to_select) and Fk:getCardById(to_select).suit == Fk:getCardById(id).suit
                end
            else
                if player:getSwitchSkillState(self.name) == fk.SwitchYang then
                    return table.contains(player.player_cards[Player.Hand],to_select) and Fk:getCardById(to_select).type == Fk:getCardById(id).type
                else
                    return table.contains(player.player_cards[Player.Hand],to_select) and Fk:getCardById(to_select).suit == Fk:getCardById(id).suit
                end
            end
        end
        return true
    end,
    target_num = 0,
    target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
        return false
    end,
    mute = true,
    on_use = function (self, room, effect)
        local player = room:getPlayerById(effect.from)
        local handCard, starCard = {}, {}
        for _, id in ipairs(effect.cards) do
            if table.contains(player.player_cards[Player.Hand],id) then
                table.insert(handCard,id)
            else
                table.insert(starCard,id)
            end
        end
        if player:getSwitchSkillState(self.name,true) == fk.SwitchYang then
            room:notifySkillInvoked(player,self.name,"drawcard")
            room:obtainCard(player, starCard, true, fk.ReasonJustMove, player.id, self.name)
            player:addToPile("$ysch4_gen", handCard, true, self.name)
        else
            local card = Fk:cloneCard(Fk:getCardById(starCard[1]).name,Fk:getCardById(starCard[1]).suit,Fk:getCardById(starCard[1]).number)
            local use = U.askForUseVirtualCard(room,player,card.name,handCard,self.name,"#ysch4_zhi_use:::"..Fk:getCardById(handCard[1]):toLogString()..":"..card:toLogString(),false,true,false,true,nil,true)
            if use then
                room:notifySkillInvoked(player,self.name,"control")
                card:addSubcards(handCard)
                use.card = card
                room:useCard(use)
            end
        end
    end,
}
yiyanqing:addSkill(lianli)
Fk:loadTranslationTable{
    ["ysch4_shouzhi"] = "手植",
    [":ysch4_shouzhi"] = "摸牌时，你可以少摸一张牌，然后将牌堆顶的两张牌正面向上置于武将牌左侧，称为“根”。当“根”出现四种花色时，你获得其中若干张牌直到“根”仅剩四种花色各一张为止。然后将这四张牌置于武将牌右侧，称为“芝”。",
    ["$ysch4_gen"] = "根",
    ["$ysch4_zhi"] = "芝",
    ["#ysch4_shouzhi-prompt"] = "是否发动 手植，少摸一张牌，将牌堆顶的两张牌置为“根”",
    ["#ysch4_shouzhi-card"] = "手植：将四种花色各一张置为“芝”，获得剩余的牌",
    ["ysch4_lianli"] = "连理",
    [":ysch4_lianli"] = "转换技，出牌阶段，你可以将一张手牌①和一张类别相同的“根”交换②当做一张花色相同的“芝”使用。",
    ["#ysch4_lianli_yang"] = "是否发动 连理，将一张手牌和一张类别相同的“根”交换",
    ["#ysch4_lianli_yin"] = "是否发动 连理，将一张手牌当做一张花色相同的“芝”使用",
    ["#ysch4_zhi_use"] = "连理：将%arg当做%arg2使用",
}
local xiean = General:new(extension, "ysch4__xiean", "jin", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__xiean"] = "谢安",
    ["#ysch4__xiean"] = "执子平澜",
    ["designer:ysch4__xiean"] = "激昂小笨笨",
    ["cv:ysch4__xiean"] = "佚名",
    ["illustrator:ysch4__xiean"] = "未知",
}
local taiyi = fk.CreateTriggerSkill{
    name = "ysch4_taiyi",
    events = {fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self) and player:usedSkillTimes(self.name,Player.HistoryRound) == 0 then
            local dat, moveEventID, moveNum = self.cost_data.dat, self.cost_data.moveEventID, self.cost_data.moveNum
            local num = 0
            for i = 1, #dat, 1 do
                if moveEventID[2] ~= dat[i][2] then
                    num = num + 1
                else
                    break
                end
            end
            if moveNum == 0 then num = 1 end
            self.cost_data.num = num
            return (moveNum == 0 or moveEventID[2] ~= player.room.logic.current_event_id + 1) and num > 0
        end
    end,
    on_cost = function (self, event, target, player, data)
        local num = self.cost_data.num
        local targets = {}
        for _, cp in ipairs(player.room.alive_players) do
            if cp:getMark("@ysch4_taiyi-lose-turn") == num then
                table.insert(targets,cp.id)
            end
        end
        if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_taiyi_draw:::"..num) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local num = self.cost_data.num
        player:drawCards(num,self.name)

        local targets = {}
        for _, cp in ipairs(player.room.alive_players) do
            if cp:getMark("@ysch4_taiyi-lose-turn") == num then
                table.insert(targets,cp.id)
            end
        end
        if #targets > 0 then
            local tos = room:askForChoosePlayers(player,targets,1,999,"#ysch4_taiyi_damage:::"..num,self.name)
            if #tos > 0 then
                room:sortPlayersByAction(tos)
                for _, id in ipairs(tos) do
                    local to = room:getPlayerById(id)
                    room:damage{
                        from = player,
                        to = to,
                        damage = 1,
                        skillName = self.name,
                    }
                end
            end
        end
    end,

    refresh_events = {fk.TurnEnd},
    can_refresh = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            local room = player.room
            local dat = {}
            local turn_events = room.logic:getEventsByRule(GameEvent.Turn, 999, function (e)
                if e.end_id < 0 then
                    table.insert(dat, {e.id, room.logic.current_event_id + 1})  --当前回合的end_id还是-1……
                else
                    table.insert(dat, {e.id, e.end_id})
                end
                return true
            end, 1)
            if #turn_events == 0 then return end
            local moveEventID = dat[1]
            local num = #room.logic:getEventsByRule(GameEvent.MoveCards, 1, function (e)
                for _, move in ipairs(e.data) do
                    if move.from == player.id then
                        for _, info in ipairs(move.moveInfo) do
                            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                                if table.find(dat, function (ids)
                                    return e.id > ids[1] and e.id < ids[2]
                                end) then
                                    moveEventID = table.find(dat, function (ids)
                                        return e.id > ids[1] and e.id < ids[2]
                                    end)
                                    return true
                                end
                            end
                        end
                    end
                end
            end, 1)
            self.cost_data = {dat = dat, moveEventID = moveEventID, moveNum = num}
            return num == 0 or moveEventID[2] ~= room.logic.current_event_id + 1
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local dat, moveEventID = self.cost_data.dat, self.cost_data.moveEventID
        local num = 0
        for i = 1, #dat, 1 do
            if moveEventID[2] ~= dat[i][2] then
                num = num + 1
            else
                break
            end
        end
        if self.cost_data.moveNum == 0 then num = 1 end
        room:setPlayerMark(player,"@ysch4_taiyi-turn",num)

        for _, cp in ipairs(room.alive_players) do
            local MoveEIds = {}
            local events = room.logic:getEventsByRule(GameEvent.MoveCards, 999, function (e)
                for _, move in ipairs(e.data) do
                    if move.from == cp.id then
                        for _, info in ipairs(move.moveInfo) do
                            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                                if table.find(dat, function (ids)
                                    return e.id > ids[1] and e.id < ids[2]
                                end) then
                                    table.insertIfNeed(MoveEIds,table.find(dat, function (ids)
                                        return e.id > ids[1] and e.id < ids[2]
                                    end)[2])
                                end
                            end
                        end
                    end
                end
            end, 1)
            local loseNum = 0
            for i = 1, #dat, 1 do
                if table.contains(MoveEIds, dat[i][2]) then
                    loseNum = loseNum + 1
                else
                    break
                end
            end
            if loseNum == num then
                room:setPlayerMark(cp,"@ysch4_taiyi-lose-turn",loseNum)
            end
        end
    end,
}
xiean:addSkill(taiyi)
local yihai = fk.CreateTriggerSkill{
    name = "ysch4_yihai",
    events = {fk.PreCardEffect},
    can_trigger = function(self, event, target, player, data)
        if player:hasSkill(self.name) and data.to == player.id and player:usedSkillTimes(self.name,Player.HistoryRound) == 0 then
            return data.card.is_damage_card and not player:isKongcheng()
            and not (data.unoffsetable or data.disresponsive or table.contains(data.unoffsetableList or {}, player.id) or table.contains(data.disresponsiveList or {}, player.id))
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local prompt = "#ysch4_yihai-prompt:::"..data.card:toLogString()

        local dat = {}
        local turn_events = room.logic:getEventsByRule(GameEvent.Turn, 999, function (e)
            if e.end_id < 0 then
                table.insert(dat, {e.id, room.logic.current_event_id + 1})  --当前回合的end_id还是-1……
            else
                table.insert(dat, {e.id, e.end_id})
            end
            return true
        end, 1)
        if #turn_events> 0 then
            local TargetEIds = {}
            local num = #room.logic:getEventsByRule(GameEvent.UseCard, 999, function (e)
                local use = e.data[1]
                if table.contains(TargetGroup:getRealTargets(use.tos), player.id) then
                    if table.find(dat, function (ids)
                        return e.id > ids[1] and e.id < ids[2]
                    end) then
                        table.insertIfNeed(TargetEIds,table.find(dat, function (ids)
                            return e.id > ids[1] and e.id < ids[2]
                        end)[2])
                    end
                end
            end, 1)

            local targetNum = 0
            for i = 1, #dat, 1 do
                if table.contains(TargetEIds, dat[i][2]) then
                    targetNum = targetNum + 1
                else
                    break
                end
            end
            local suits = {}
            for _, id in ipairs(player:getCardIds("h")) do
                table.insertIfNeed(suits, Fk:getCardById(id).suit)
            end
            if targetNum == #suits and player:isWounded() then
                self.cost_data = "Recover"
                prompt = "#ysch4_yihai-recover:::"..data.card:toLogString()
            end
        end

        if room:askForSkillInvoke(player, self.name, data, prompt) then
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        player:showCards(player.player_cards[Player.Hand])
        if self.cost_data == "Recover" then
            player.room:recover({ who = player, num = 1, skillName = self.name})
        end
        return true
    end,
}
xiean:addSkill(yihai)
Fk:loadTranslationTable{
    ["ysch4_taiyi"] = "泰屹",
    [":ysch4_taiyi"] = "轮次技，一个回合结束时，你每连续一个回合未失去过牌，你便可摸一张牌，若有角色连续等量回合失去过牌，你可对其造成1点伤害。",
    ["#ysch4_taiyi_draw"] = "是否发动 泰屹，摸 %arg 张牌",
    ["#ysch4_taiyi_damage"] = "泰屹：你可以对任意名连续%arg回合失去过牌的角色造成1点伤害",
    ["@ysch4_taiyi-turn"] = "未失回合数",
    ["@ysch4_taiyi-lose-turn"] = "连失回合数",
    ["ysch4_yihai"] = "弈海",
    [":ysch4_yihai"] = "轮次技，你可展示所有手牌以响应一张伤害牌，若你已连续其中花色数个回合成为过牌的目标，你回复1点体力。",
    ["#ysch4_yihai-prompt"] = "是否发动 弈海，展示所有手牌以响应%arg",
    ["#ysch4_yihai-recover"] = "是否发动 弈海，展示所有手牌以响应%arg；然后你回复1点体力",
}
local weiqi = General:new(extension, "ysch4__weiqi", "jin", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__weiqi"] = "魏锜",
    ["#ysch4__weiqi"] = "厚瘗射月",
    ["designer:ysch4__weiqi"] = "森伯十夜",
    ["cv:ysch4__weiqi"] = "佚名",
    ["illustrator:ysch4__weiqi"] = "率土之滨",
}
local guanjiao = fk.CreateTriggerSkill{
    name = "ysch4_guanjiao",
    events = {fk.DamageFinished},
    can_trigger = function (self, event, target, player, data)
        return player:hasSkill(self.name) and ((data.from and data.from == player) or target == player)
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        while true do
            local choice = room:askForChoice(player,{"#ysch4_kongxian1","#ysch4_kongxian2","#ysch4_kongxian3","Cancel"},self.name,"#ysch4_guanjiao-prompt1",false)
            if choice ~= "Cancel" then
                local top = room:askForChoice(player,{"#ysch4_guanjiao1","#ysch4_guanjiao2","Back"},self.name,"#ysch4_guanjiao-prompt2")
                if top ~= "Back" then
                    self.cost_data = {choice = choice,top = top}
                    return true
                end
            else
                break
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local choice, top = self.cost_data.choice, self.cost_data.top
        local skills = {}
        if top == "#ysch4_guanjiao1" then
            for _, skill in ipairs(player.player_skills) do
                local name = skill.name
                local str = Fk:translate(":"..name,"zh_CN")
                if str and str ~= "" and not string.find(name,"#") and skill:isPlayerSkill(player) and not skill:isEquipmentSkill(player) then
                    table.insertIfNeed(skills,name)
                end
            end
            if #skills > 0 then
                room:handleAddLoseSkills(player,"-"..table.concat(skills,"|-"),nil,false,true)
            end
        end
        local skill = "ysch4_kongxian"
        for i = 1, 50, 1 do
            skill = "yschA"..i.."_kongxian"
            if choice == "#ysch4_kongxian2" then
                skill = "yschB"..i.."_kongxian"
            elseif choice == "#ysch4_kongxian3" then
                skill = "yschC"..i.."_kongxian"
            end
            if not player:hasSkill(skill) then
                room:handleAddLoseSkills(player,skill,nil,false,true)
                break
            end
        end
        if #skills > 0 then
            room:handleAddLoseSkills(player,table.concat(skills,"|"),nil,false,true)
        end
        room:sendLog{
            type = "#AcquireSkill",
            from = player.id,
            arg = skill
        }
        room.logic:trigger(fk.EventAcquireSkill, player, Fk.skills[skill])
    end,
}
weiqi:addSkill(guanjiao)
local pochen = fk.CreateTriggerSkill{
    name = "ysch4_pochen",
    events = {fk.AfterSkillEffect},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and target == player and data.name ~= self.name then
            local skills = {}
            for _, skill in ipairs(player.player_skills) do
                local name = skill.name
                local str = Fk:translate(":"..name,"zh_CN")
                if str and str ~= "" and not string.find(name,"#") and skill:isPlayerSkill(player) and not skill:isEquipmentSkill(player) then
                    table.insertIfNeed(skills,name)
                end
            end
            p(skills)
            --p(#skills%2==0)
            if #skills%2==0 then
                p(skills[#skills/2])
                p(skills[(#skills/2)+1])
                return skills[#skills/2] == data.name or skills[(#skills/2)+1] == data.name
            else
                p(skills[(#skills+1)/2])
                return skills[(#skills+1)/2] == data.name
            end
        end
    end,
    on_cost = function(self, event, target, player, data)
        local use = U.askForUseVirtualCard(player.room, player, "ysch_Al_shot__slash", nil, self.name, "#ysch4_pochen-use", true, true, false, true, nil, true)
        if use then
            self.cost_data = use
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:useCard(self.cost_data)

        if data.name == "ysch4_guanjiao" and player:getHandcardNum() ~= 4 then
            if player:getHandcardNum() < 4 then
                player:drawCards(4 - player:getHandcardNum(), self.name)
            else
                room:askForDiscard(player,player:getHandcardNum()-4,player:getHandcardNum()-4,false,self.name,false,nil,"#ysch4_pochen-discard")
            end
        end
    end,
}
weiqi:addSkill(pochen)
for loop = 1, 50, 1 do
    local kongxianA = fk.CreateTriggerSkill{
        name = "yschA"..loop.."_kongxian",
        events = {fk.TurnEnd},
        frequency = Skill.Compulsory,
        anim_type = "negative",
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) then
                if #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                    for _, move in ipairs(e.data) do
                      if
                        move.from == player.id and
                        not (move.to == player.id and (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip))
                      then
                        return
                          table.find(
                            move.moveInfo,
                            function(info) return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip end
                          ) ~= nil
                      end
                    end
                    return false
                end, Player.HistoryTurn) > 0 then
                    return true
                end
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local Askills = {}
            for _, skill in ipairs(player.player_skills) do
                --local name = Fk:translate(skill.name, "zh_CN")
                if string.find(skill.name,"kongxian") then
                    if string.find(skill.name,"yschA") then
                        table.insert(Askills,skill.name)
                    end
                end
            end
            room:handleAddLoseSkills(player,"-"..table.concat(Askills,"|-"))
        end,
    }
    local kongxianB = fk.CreateTriggerSkill{
        name = "yschB"..loop.."_kongxian",
        events = {fk.TurnEnd},
        frequency = Skill.Compulsory,
        anim_type = "negative",
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) then
                if #player.room.logic:getActualDamageEvents(1, function(e)
                    return e.data[1].to == player
                  end) > 0 then
                    return true
                end
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local skills = {}
            for _, skill in ipairs(player.player_skills) do
                --local name = Fk:translate(skill.name, "zh_CN")
                if string.find(skill.name,"kongxian") then
                    if string.find(skill.name,"yschB") then
                        table.insert(skills,skill.name)
                    end
                end
            end
            room:handleAddLoseSkills(player,"-"..table.concat(skills,"|-"))
        end,
    }
    local kongxianC = fk.CreateTriggerSkill{
        name = "yschC"..loop.."_kongxian",
        events = {fk.TurnEnd},
        frequency = Skill.Compulsory,
        anim_type = "negative",
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) then
                if #player.room.logic:getActualDamageEvents(1, function(e)
                    return (e.data[1].from and e.data[1].from == player) or e.data[1].to == player
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                    for _, move in ipairs(e.data) do
                        if move.from == player.id or move.to == player.id then
                            return true
                        end
                    end
                    return false
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Recover, 1, function(e)
                    return e.data[1].who == player or e.data[1].from == player.id
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                    local d = e.data[1]
                    return d.from == player.id or (d.tos and table.contains(TargetGroup:getRealTargets(d.tos), player.id))
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
                    return e.data[1].from == player.id
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
                    return e.data[1] == player
                end, Player.HistoryTurn)  == 0 and #player.room.logic:getEventsOfScope(GameEvent.Pindian, 999, function(e)
                    local dat = e.data[1]
                    if dat.from == player or dat.results[player.id] or table.contains(dat.tos, player) then
                        return true
                    end
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
                    return e.data.from == player
                end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeProperty, 1, function(e)
                    local dat = e.data[1]
                    return dat.from == player and dat.results and dat.results["kingdomChange"]
                end, Player.HistoryTurn) == 0 then
                    return true
                end
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local skills = {}
            for _, skill in ipairs(player.player_skills) do
                --local name = Fk:translate(skill.name, "zh_CN")
                if string.find(skill.name,"kongxian") then
                    if string.find(skill.name,"yschC") then
                        table.insert(skills,skill.name)
                    end
                end
            end
            room:handleAddLoseSkills(player,"-"..table.concat(skills,"|-"))
        end,
    }
    Fk:addSkill(kongxianA)
    Fk:addSkill(kongxianB)
    Fk:addSkill(kongxianC)
    Fk:loadTranslationTable{
        ["yschA"..loop.."_kongxian"] = "控弦",
        [":yschA"..loop.."_kongxian"] = "锁定技，你失去过牌的回合结束时，你失去所有与此技能触发时机相同的技能。",
        ["yschB"..loop.."_kongxian"] = "控弦",
        [":yschB"..loop.."_kongxian"] = "锁定技，你受到过伤害的回合结束时，你失去所有与此技能触发时机相同的技能。",
        ["yschC"..loop.."_kongxian"] = "控弦",
        [":yschC"..loop.."_kongxian"] = "锁定技，你未行动过的回合结束时，你失去所有与此技能触发时机相同的技能。",
    }
end
local kongxian = fk.CreateTriggerSkill{
    name = "ysch4_kongxian",
    events = {fk.TurnEnd},
    frequency = Skill.Compulsory,
    anim_type = "negative",
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            if #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                for _, move in ipairs(e.data) do
                  if
                    move.from == player.id and
                    not (move.to == player.id and (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip))
                  then
                    return
                      table.find(
                        move.moveInfo,
                        function(info) return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip end
                      ) ~= nil
                  end
                end
                return false
            end, Player.HistoryTurn) > 0 then
                self.cost_data = 1
                return true
            end
            if #player.room.logic:getActualDamageEvents(1, function(e)
                return e.data[1].to == player
            end, Player.HistoryTurn) > 0 then
                self.cost_data = 2
                return true
            end
            if #player.room.logic:getActualDamageEvents(1, function(e)
                return (e.data[1].from and e.data[1].from == player) or e.data[1].to == player
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
                for _, move in ipairs(e.data) do
                    if move.from == player.id or move.to == player.id then
                        return true
                    end
                end
                return false
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Recover, 1, function(e)
                return e.data[1].who == player or e.data[1].from == player.id
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                local d = e.data[1]
                return d.from == player.id or (d.tos and table.contains(TargetGroup:getRealTargets(d.tos), player.id))
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
                return e.data[1].from == player.id
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeHp, 1, function(e)
                return e.data[1] == player
            end, Player.HistoryTurn)  == 0 and #player.room.logic:getEventsOfScope(GameEvent.Pindian, 999, function(e)
                local dat = e.data[1]
                if dat.from == player or dat.results[player.id] or table.contains(dat.tos, player) then
                    return true
                end
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
                return e.data.from == player
            end, Player.HistoryTurn) == 0 and #player.room.logic:getEventsOfScope(GameEvent.ChangeProperty, 1, function(e)
                local dat = e.data[1]
                return dat.from == player and dat.results and dat.results["kingdomChange"]
            end, Player.HistoryTurn) == 0 then
                self.cost_data = 3
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local Askills, Bskills, Cskills = {}, {}, {}
        for _, skill in ipairs(player.player_skills) do
            --local name = Fk:translate(skill.name, "zh_CN")
            if string.find(skill.name,"kongxian") then
                if string.find(skill.name,"yschA") then
                    table.insert(Askills,skill.name)
                elseif string.find(skill.name,"yschB") then
                    table.insert(Bskills,skill.name)
                elseif string.find(skill.name,"yschC") then
                    table.insert(Cskills,skill.name)
                end
            end
        end
        if self.cost_data == 1 then
            room:handleAddLoseSkills(player,"-"..table.concat(Askills,"|-"))
        elseif self.cost_data == 2 then
            room:handleAddLoseSkills(player,"-"..table.concat(Bskills,"|-"))
        elseif self.cost_data == 3 then
            room:handleAddLoseSkills(player,"-"..table.concat(Cskills,"|-"))
        end
    end,
}
weiqi:addRelatedSkill(kongxian)
Fk:loadTranslationTable{
    ["ysch4_guanjiao"] = "贯皎",
    [":ysch4_guanjiao"] = "你参与伤害结算后，可获得一个仅有一个触发时机的“控弦”作为首个或最后一个技能。"..
    "<br/><font color='grey'><b>注</b>：这里的触发时机按设计师本意仅指“控弦”的一个发动限制</font>",
    ["#ysch4_guanjiao1"] = "首",
    ["#ysch4_guanjiao2"] = "尾",
    ["Back"] = "返回",
    ["#ysch4_guanjiao-prompt1"] = "是否发动 贯皎，获得仅有一个时机的“控弦”",
    ["#ysch4_guanjiao-prompt2"] = "贯皎：请选择要获得“控弦”的位置",
    ["ysch4_pochen"] = "破宸",
    [":ysch4_pochen"] = "你触发最中间的其他技能后，可视为使用射【杀】；若为“贯皎”，则你再将手牌调整至4。",
    ["#ysch4_pochen-use"] = "是否发动 破宸，视为使用射【杀】",
    ["#ysch4_pochen-discard"] = "破宸：将手牌调整至4",
    ["ysch4_kongxian"] = "控弦",
    [":ysch4_kongxian"] = "锁定技，你失去过牌/受到过伤害/未行动过的回合结束时，你失去所有与此技能触发时机相同的技能。"..
    "<br/><font color='grey'><b>注</b>：这里的触发时机按设计师本意仅指“控弦”的一个发动限制</font>",
    ["#ysch4_kongxian1"] = "失去过牌的回合结束时",
    ["#ysch4_kongxian2"] = "受过伤害的回合结束时",
    ["#ysch4_kongxian3"] = "未行动过的回合结束时",
}
local chenwudongxi = General:new(extension, "ysch4__chenwudongxi", "wu", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__chenwudongxi"] = "陈武董袭",
    ["#ysch4__chenwudongxi"] = "浪里徐行",
    ["designer:ysch4__chenwudongxi"] = "屑",
    ["cv:ysch4__chenwudongxi"] = "佚名",
    ["illustrator:ysch4__chenwudongxi"] = "未知",
}
local jielei = fk.CreateViewAsSkill{
    name = "ysch4_jielei",
    anim_type = "special",
    pattern = ".|.|.|.|thunder__slash,iron_chain",
    interaction = function(self)
        local all_names = {"iron_chain", "thunder__slash"}
        local names = U.getViewAsCardNames(Self, self.name, all_names)
        if #names > 0 then
            return U.CardNameBox { choices = names, all_choices = all_names }
        end
    end,
    view_as = function (self, cards, player)
        if #cards == 0 or not self.interaction.data then return nil end
        local card = Fk:cloneCard(self.interaction.data)
        card:addSubcards(cards)
        card.skillName = self.name
        return card
    end,
    card_num = 1,
    card_filter = function (self, to_select, selected, player)
        return #selected == 0 and Fk:getCardById(to_select).color == Card.Black
    end,
    before_use = function (self, player, use)
        player.room:setPlayerMark(player,"ysch4_jielei-phase",{})
    end,
    after_use = function (self, player, use)
        if #player:getTableMark("ysch4_jielei-phase") == 1 then
            local room = player.room
            local to = room:getPlayerById(player:getTableMark("ysch4_jielei-phase")[1])
            --[[local ids = table.filter(to:getCardIds("h"),function (id)
                return Fk:getCardById(id).is_damage_card
            end)]]--
            local names = {}
            for _, name in ipairs(getAllCardNames("bt",true)) do
                local card = Fk:cloneCard(name)
                if card.is_damage_card and not card.multiple_targets then
                    table.insertIfNeed(names,name)
                end
            end
            local toUse = room:askForUseCard(to, self.name, tostring(Exppattern{ trueName = names}),
                "#ysch4_jielei-use1", true, {bypass_times = true, extraUse = true})
            if toUse then
                toUse.extraUse = true
                room:useCard(toUse)
                if room:askForSkillInvoke(player,self.name,nil,"#ysch4_jielei-recast2") then
                    player:drawCards(1, "recast")
                end
            elseif #to:getCardIds("he") > 0 then
                local recastCards = room:askForCard(to, 1, 1, true, self.name, false, ".", "#ysch4_jielei-recast1")
                room:recastCard(recastCards, to, self.name)
                local cards = U.getUniversalCards(room, "bt", false)
                cards = table.filter(cards,function (id)
                    local cd = Fk:getCardById(id)
                    return cd.is_damage_card and not cd.multiple_targets
                end)
                local playerUse = U.askForUseRealCard(room, player, cards, nil, self.name, "#ysch4_jielei-use2",
                {expand_pile = cards, bypass_times = true, extraUse = true}, true, true)
                if playerUse then
                    playerUse.card = Fk:cloneCard(playerUse.card.name)
                    playerUse.card.skillName = self.name
                    playerUse.extraUse = true
                    room:useCard(playerUse)
                end
            end
        end
        player.room:setPlayerMark(player,"ysch4_jielei-phase",0)
    end,
    enabled_at_response = function (self, player, response)
        return not response
    end,
}
local jielei_trigger = fk.CreateTriggerSkill{
    name = "#ysch4_jielei_trigger",
    refresh_events = {fk.ChainStateChanged},
    can_refresh = function (self, event, target, player, data)
        if not target.chained then
            local ParentEvent = player.room.logic:getCurrentEvent().parent
            if ParentEvent and ParentEvent.event then
                if ParentEvent.event.name == "GameEvent.CardEffect" then
                    local ParentParentEvent = ParentEvent.parent.data[1]
                    p(ParentParentEvent)
                    return ParentParentEvent.card.skillName == "ysch4_jielei"
                elseif ParentEvent.event.name == "GameEvent.Damage" then
                    local ParentParentEvent = ParentEvent.data[1]
                    return ParentParentEvent and ParentParentEvent.from and ParentParentEvent.from == player and ParentParentEvent.card and ParentParentEvent.card.skillName == "ysch4_jielei"
                end
            end
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local room = player.room
        local mark = player:getTableMark("ysch4_jielei-phase")
        table.insertIfNeed(mark,target.id)
        room:setPlayerMark(player,"ysch4_jielei-phase",mark)
    end,
}
jielei:addRelatedSkill(jielei_trigger)
chenwudongxi:addSkill(jielei)
Fk:loadTranslationTable{
    ["ysch4_jielei"] = "解缧",
    [":ysch4_jielei"] = "你可以将一张黑色牌当【铁索连环】或雷【杀】使用，结算后若此牌恰使一名角色脱离横置，其须执行一项，然后你可以视为执行另一项：1.使用一张单体伤害牌；2.重铸一张牌。",
    ["#ysch4_jielei-use1"] = "解缧：你可以使用一张伤害牌或点 “取消” 然后重铸一张牌。",
    ["#ysch4_jielei-recast1"] = "解缧：重铸一张牌。",
    ["#ysch4_jielei-use2"] = "解缧：你可以视为使用一张伤害牌。",
    ["#ysch4_jielei-recast2"] = "解缧：你可以视为重铸一张牌。",

    ["$ysch4_jielei1"] = "区区绳索就想挡住吾等去路？！",
    ["$ysch4_jielei2"] = "以身索敌，何惧同伤！",
    ["~ysch4__chenwudongxi"] = "杀身卫主，死而无憾！",
}
local xunchen = General:new(extension, "ysch4__xunchen", "qun", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__xunchen"] = "荀谌",
    ["#ysch4__xunchen"] = "空言夺壁",
    ["designer:ysch4__xunchen"] = "肠肠陛下",
    ["cv:ysch4__xunchen"] = "佚名",
    ["illustrator:ysch4__xunchen"] = "未知",
}
local fenglve = fk.CreateActiveSkill{
    name = "ysch4_fenglve",
    anim_type = "offensive",
    card_num = 0,
    target_num = 1,
    can_use = function(self, player)
        return not player:isKongcheng() and player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = Util.FalseFunc,
    target_filter = function(self, to_select, selected, selected_cards)
        return #selected == 0 and to_select ~= Self.id and Self:canPindian(Fk:currentRoom():getPlayerById(to_select))
    end,
    on_use = function(self, room, effect)
        local player = room:getPlayerById(effect.from)
        local target = room:getPlayerById(effect.tos[1])
        local pindian = player:pindian({target}, self.name)
        local to = target
        local winner = pindian.results[target.id].winner
        if winner and not winner.dead then
            if winner ~= player then
                to = player
            end
            if not to.dead then
                local card = Fk:cloneCard("ysch_Al__sincere_treat")
                card.skillName = self.name
                room:useCard{
                    from = winner.id,
                    card = card,
                    tos = { { to.id } },
                    extraUse = true,
                }
            end
            if winner == player and not player.dead then
                local cards = room:askForCard(player, 0, 2, false, self.name, false, nil, "#ysch4_fenglve-card")
                if #cards > 0 then
                    room:moveCardTo(cards, Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true)
                end
                if not player.dead then
                    local use = U.askForUseVirtualCard(room, player, "ysch_Al__enemy_at_the_gates", nil, self.name, "#ysch4_fenglve-use", false)
                end
            end
        end
    end,
}
xunchen:addSkill(fenglve)
local anyong = fk.CreateTriggerSkill{
    name = "ysch4_anyong",
    events = {fk.TurnEnd},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) then
            self.cost_data = {}
            return #player.room.logic:getActualDamageEvents(1, function(e)
                if string.find(Fk:translate(e.data[1].from.general,"zh_CN"),"荀谌") or (e.data[1].from.deputyGeneral and string.find(Fk:translate(e.data[1].from.deputyGeneral,"zh_CN"),"荀谌")) then
                    table.insertIfNeed(self.cost_data,e.data[1].from.id)
                    return true
                end
                return false
            end) > 0
        end
    end,
    frequency = Skill.Compulsory,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local tos = self.cost_data
        table.insert(tos,player.id)
        local ids = {}
        room:sortPlayersByAction(tos)
        for _, to in ipairs(table.map(tos,Util.Id2PlayerMapper)) do
            if not to.dead then
                local draws = to:drawCards(1, self.name)
                if to == player then
                    table.insertTableIfNeed(ids,draws)
                end
            end
        end

        local cards = table.filter(player:getCardIds("h"),function (id)
            return not table.contains(ids,id)
        end)
        local result = room:askForDiscard(player,1,1,false,self.name,true,tostring(Exppattern{id = cards}),"#ysch4_anyong-discard")
        if #result > 0 then
            room:handleAddLoseSkills(player,"-"..self.name)
            room:handleAddLoseSkills(room:getPlayerById(player:getNextAlive().id),self.name)
        else
            for _, to in ipairs(table.map(tos,Util.Id2PlayerMapper)) do
                if not to.dead then
                    if to ~= player and not player:isNude() then
                        local id = room:askForCardChosen(to, player, "he", self.name)
                        room:moveCardTo(id, Card.PlayerHand, to, fk.ReasonPrey, self.name, nil, false, to.id)
                    end
                end
            end
        end
    end,
}
xunchen:addSkill(anyong)
Fk:loadTranslationTable{
    ["ysch4_fenglve"] = "锋略",
    [":ysch4_fenglve"] = "阶段技，你可以拼点，赢者视为对输者使用【推心置腹】，且若你赢，结算后你可以将至多两张手牌置于牌堆顶并视为使用【兵临城下】。",
    ["#ysch4_fenglve-card"] = "锋略：你可以将至多两张手牌置于牌堆顶，然后视为使用【兵临城下】",
    ["#ysch4_fenglve-use"] = "锋略：视为使用【兵临城下】",
    ["ysch4_anyong"] = "暗涌",
    [":ysch4_anyong"] = "锁定技，荀谌造成过伤害的回合结束时，其与你各摸一张牌，然后你选择:1.荀谌获得你一张牌；2.弃置另一张手牌以将此技能交给下家。",
    ["#ysch4_anyong-discard"] = "暗涌：弃置另一张手牌以将此技能交给下家，或点“取消”令荀谌获得你一张牌",

    ["$ysch4_fenglve1"] = "当今敢称贤者，唯袁氏本初一人。",
    ["$ysch4_fenglve2"] = "冀州宝地，本当贤者居之。",
    ["$ysch4_anyong1"] = "殿上太守且相看，殿下几人还拥韩。",
    ["$ysch4_anyong2"] = "冀州暗潮汹涌，群仕居危思变。",
    ["~ysch4__xunchen"] = "为臣当不贰，贰臣不当为。",
}
local dengai = General:new(extension, "ysch4__dengai", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__dengai"] = "邓艾",
    ["#ysch4__dengai"] = "青天横跃",
    ["designer:ysch4__dengai"] = "伶",
    ["cv:ysch4__dengai"] = "佚名",
    ["illustrator:ysch4__dengai"] = "未知",
}
local xianjin_bogusFlowerSkill = fk.CreateActiveSkill{
    name = "#xianjin_ysch_Al__bogus_flower_skill",
    mute = true,
    mod_target_filter = Util.TrueFunc,
    on_use = function(self, room, cardUseEvent)
        if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
            cardUseEvent.tos = { { cardUseEvent.from } }
        end
    end,
    on_effect = function(self, room, effect)
        local target = room:getPlayerById(effect.to)
        if target.dead or target:isNude() then return end
        local cards = room:askForDiscard(target, 1, 2, true, "ysch_Al__bogus_flower", false, ".", "#ysch_Al__bogus_flower-discard", true)
        if #cards == 0 then return end
        local n = #cards
        if table.find(cards, function(id) return Fk:getCardById(id).type == Card.TypeEquip end) then
            n = n + 1
        end
        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if use_event then
            local use = use_event.data[1]
            use.extra_data = use.extra_data or {}
            use.extra_data.ysch4_xianjin = use.extra_data.ysch4_xianjin or {}
            table.insertTableIfNeed(use.extra_data.ysch4_xianjin, cards)
        end
        room:throwCard(cards, "ysch_Al__bogus_flower", target, target)
        if not target.dead then
            target:drawCards(n, "ysch_Al__bogus_flower")
        end
    end
}
Fk:addSkill(xianjin_bogusFlowerSkill)
local xianjin_snatchSkill = fk.CreateActiveSkill{
    name = "#xianjin_snatch_skill",
    prompt = "#snatch_skill",
    can_use = Util.CanUse,
    distance_limit = 1,
    mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
      local target = Fk:currentRoom():getPlayerById(to_select)
      return target ~= player and not (target:isAllNude() or (distance_limited and not self:withinDistanceLimit(player, false, card, target)))
    end,
    target_filter = Util.TargetFilter,
    target_num = 1,
    mute = true,
    on_effect = function(self, room, effect)
        local from = room:getPlayerById(effect.from)
        local to = room:getPlayerById(effect.to)
        if from.dead or to.dead or to:isAllNude() then return end
        local cid = room:askForCardChosen(from, to, "hej", self.name)
        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
        if use_event then
            local use = use_event.data[1]
            use.extra_data = use.extra_data or {}
            use.extra_data.ysch4_xianjin = use.extra_data.ysch4_xianjin or {}
            table.insertIfNeed(use.extra_data.ysch4_xianjin, cid)
        end
        room:obtainCard(from, cid, false, fk.ReasonPrey)
    end
}
Fk:addSkill(xianjin_snatchSkill)
local xianjin = fk.CreateTriggerSkill{
    name = "ysch4_xianjin",
    events = {fk.EventPhaseEnd},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and target == player then
            if player.phase == Player.Draw then
                return not player:isNude()
            end
            if player.phase == Player.Play then
                return player:getMark("@@ysch4_xianjin1-turn") ~= 0
            end
            if player.phase == Player.Discard then
                return player:getMark("@@ysch4_xianjin2-turn") ~= 0
            end
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local name = ""
        if player.phase == Player.Draw then
            name = "ysch_Al__bogus_flower"
        elseif player.phase == Player.Play then
            name = "snatch"
            room:setPlayerMark(player,"@@ysch4_xianjin1-turn",0)
        elseif player.phase == Player.Discard then
            name = "ysch_Al__unexpectation"
            room:setPlayerMark(player,"@@ysch4_xianjin2-turn",0)
        end
        if name ~= "" then
            local prompt = "#ysch4_xianjin:::"..name
            local success, dat =  room:askForUseViewAsSkill(player,"#ysch4_xianjin_viewas",prompt,true,{ysch4_xianjin = name})
            if success then
                self.cost_data = dat
                return true
            end
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local dat = self.cost_data
        local name = "ysch_Al__bogus_flower"
        if player.phase == Player.Play then
            name = "snatch"
        elseif player.phase == Player.Discard then
            name = "ysch_Al__unexpectation"
        end
        if #dat.targets == 0 then
            dat.targets = {player.id}
        end
        local use = room:useVirtualCard(name, dat.cards, player, table.map(dat.targets, function(id) return room:getPlayerById(id) end), self.name)
        if use then
            if player.phase == Player.Discard then
                if table.find(dat.cards,function (id)
                    local card = Fk:getCardById(id)
                    return card.type == Card.TypeTrick
                end) then
                    player:drawCards(3,self.name)
                end
            elseif use.extra_data and use.extra_data.ysch4_xianjin then
                local cards = use.extra_data.ysch4_xianjin
                if player.phase == Player.Draw then
                    if table.find(cards,function (id)
                        local card = Fk:getCardById(id)
                        return card.type == Card.TypeEquip
                    end) then
                        room:setPlayerMark(player,"@@ysch4_xianjin1-turn",1)
                    end
                else
                    if table.find(cards,function (id)
                        local card = Fk:getCardById(id)
                        return card.type == Card.TypeBasic
                    end) then
                        room:setPlayerMark(player,"@@ysch4_xianjin2-turn",1)
                    end
                end
            end
        end
    end,

    refresh_events = {fk.PreCardEffect},
    can_refresh = function (self, event, target, player, data)
        if table.contains({"bogus_flower","snatch"},data.card.trueName) then
            return data.card.skillName == self.name
        end
    end,
    on_refresh = function (self, event, target, player, data)
        local card = data.card:clone()
        local c = table.simpleClone(data.card)
        for k, v in pairs(c) do
            card[k] = v
        end
        if data.card.trueName == "bogus_flower" then
            card.skill = xianjin_bogusFlowerSkill
        else
            card.skill = xianjin_snatchSkill
        end
        data.card = card
    end,
}
local xianjin_viewas = fk.CreateViewAsSkill{
    name = "#ysch4_xianjin_viewas",
    card_num = 1,
    handly_pile = true,
    card_filter = function(self, to_select, selected)
      return #selected == 0
    end,
    view_as = function(self, cards)
        if #cards ~= 1 or not self.ysch4_xianjin then return end
        local card = Fk:cloneCard(self.ysch4_xianjin)
        card:addSubcard(cards[1])
        card.skillName = "ysch4_xianjin"
        return card
    end,
}
dengai:addSkill(xianjin)
Fk:addSkill(xianjin_viewas)
local jiewan = fk.CreateTriggerSkill{
    name = "ysch4_jiewan",
    events = {fk.AfterTurnEnd},
    can_trigger = function (self, event, target, player, data)
        if player:hasSkill(self.name) and target == player then
            return not player:insideExtraTurn()
        end
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local slots = player:getAvailableEquipSlots()
        if #slots == 0 then return end
        table.insert(slots,"Cancel")
        local slot = room:askForChoice(player, slots, self.name, "#ysch4_jiewan-abort")
        if slot ~= "Cancel" then
            self.cost_data = slot
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        room:abortPlayerArea(player, self.cost_data)
        player:gainAnExtraTurn(true, self.name)
    end,

    refresh_events = {fk.TurnStart},
    can_refresh = function (self, event, target, player, data)
        return target == player and player:getCurrentExtraTurnReason() == self.name
    end,
    on_refresh = function (self, event, target, player, data)
        player.room:setPlayerMark(player,"@@ysch4_jiewan-turn",1)
    end,
}
local jiewan_prohibit = fk.CreateProhibitSkill{
    name = "#ysch4_jiewan_prohibit",
    prohibit_use = function(self, player, card)
        return card and not card:isVirtual() and #card.subcards == 0 and player:getMark("@@ysch4_jiewan-turn") > 0 and card.skillName ~= "ysch4_jiewan"
    end,
}
jiewan:addRelatedSkill(jiewan_prohibit)
dengai:addSkill(jiewan)
Fk:loadTranslationTable{
    ["ysch4_xianjin"] = "险进",
    [":ysch4_xianjin"] = "摸牌阶段结束时，你可以将一张牌当【树上开花】使用；若因此弃置了装备牌，则出牌阶段结束时，你可以将一张牌当【顺手牵羊】使用；若因此获得了基本牌，则弃牌阶段结束时，你可以将一张牌当【出其不意】使用；若因此转化了锦囊牌，你摸三张牌。",
    ["@@ysch4_xianjin1-turn"] = "险进 顺手牵羊",
    ["@@ysch4_xianjin2-turn"] = "险进 出其不意",
    ["#ysch4_xianjin"] = "是否发动 险进，将一张牌当【%arg】使用",
    ["ysch4_jiewan"] = "解腕",
    [":ysch4_jiewan"] = "额定回合结束时，你可以废除一个装备栏，执行一个只能使用转化牌的额外回合。",
    ["#ysch4_jiewan-abort"] = "是否发动 解腕，废除一个装备栏，执行一个额外回合",
    ["@@ysch4_jiewan-turn"] = "解腕 禁非转化",
}
local huamulan = General:new(extension, "ysch4__huamulan", "wei", 4, 4, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__huamulan"] = "花木兰",
    ["#ysch4__huamulan"] = "血征孤蔷",
    ["designer:ysch4__huamulan"] = "静谦",
    ["cv:ysch4__huamulan"] = "佚名",
    ["illustrator:ysch4__huamulan"] = "未知",
}
if huamulan then
    local fuguan = fk.CreateTriggerSkill{
        name = "ysch4_fuguan",
        events = {fk.TurnEnd},
        anim_type = "drawcard",
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) then
                local room = player.room
                local names = {}
                room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
                    for _, move in ipairs(e.data) do
                        if move.from == player.id and
                        not (move.to == player.id and (move.toArea == Card.PlayerHand or move.toArea == Card.PlayerEquip))
                        then
                            for _, info in ipairs(move.moveInfo) do
                                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                                    local card = Fk:getCardById(info.cardId)
                                    if card.trueName == "jink" then
                                        table.insertIfNeed(names,"#ysch4_fuguan2")
                                    end
                                    if card.type == Card.TypeEquip then
                                        table.insertIfNeed(names,"#ysch4_fuguan1")
                                    end
                                    if #names > 1 then break end
                                end
                            end
                        end
                    end
                end, Player.HistoryTurn)
                if #names > 0 then
                    self.cost_data = names
                    return true
                end
            end
        end,
        on_cost = function (self, event, target, player, data)
            local room = player.room
            if room:askForSkillInvoke(player,self.name,nil,"#ysch4_fuguan-prompt:::"..table.concat(self.cost_data)) then
                return true
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local cards, ids = {}, {}
            while true do
                local id = room:getNCards(1)[1]
                room:moveCardTo(id, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
                room:delay(200)
                local card = Fk:getCardById(id)
                if card.trueName == "slash" then
                    table.insert(cards, id)
                    table.insert(ids, id)
                elseif card.trueName == "jink" and table.contains(self.cost_data,"#ysch4_fuguan1") then
                    room:obtainCard(player,id,true,fk.ReasonJustMove,player.id,self.name)
                    break
                elseif card.type == Card.TypeEquip and table.contains(self.cost_data,"#ysch4_fuguan2") then
                    room:obtainCard(player,id,true,fk.ReasonJustMove,player.id,self.name)
                    break
                else
                    table.insert(cards, id)
                end
            end
            room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
            if #ids > 0 then
                for _, id in ipairs(ids) do
                    local use = U.askForUseRealCard(room, player, {id}, nil, self.name,
                    "#ysch4_fuguan-use", {bypass_times = true,extraUse = true,expand_pile = {id},}, false, true)
                    if not use then
                        break
                    end
                end
            end
        end,
    }
    huamulan:addSkill(fuguan)
    local rongzhuang = fk.CreateTriggerSkill{
        name = "ysch4_rongzhuang",
        refresh_events = {fk.AfterCardsMove,fk.HpChanged,fk.MaxHpChanged},
        can_refresh = function (self, event, target, player, data)
            return player:hasSkill(self.name)
        end,
        on_refresh = function (self, event, target, player, data)
            local room = player.room
            local num = player.hp - #player:getCardIds("e")
            if num > 0 then
                player.gender = General.Female
                room:handleAddLoseSkills(player,"biyue|-wushuang",nil,false,true)
                room:broadcastProperty(player, "gender")
            else
                player.gender = General.Male
                room:handleAddLoseSkills(player,"-biyue|wushuang",nil,false,true)
                room:broadcastProperty(player, "gender")
            end
        end,
        on_acquire = function (self, player, is_start)
            local room = player.room
            local num = player.hp - #player:getCardIds("e")
            if num > 0 then
                player.gender = General.Female
                room:handleAddLoseSkills(player,"biyue|-wushuang",nil,false,true)
                room:broadcastProperty(player, "gender")
            else
                player.gender = General.Male
                room:handleAddLoseSkills(player,"-biyue|wushuang",nil,false,true)
                room:broadcastProperty(player, "gender")
            end
        end,
        on_lose = function (self, player, is_death)
            local room = player.room
            room:handleAddLoseSkills(player,"-biyue|-wushuang",nil,false,true)
            player.gender = Fk.generals[player.general].gender
            room:broadcastProperty(player, "gender")
        end,
    }
    huamulan:addSkill(rongzhuang)
    huamulan:addRelatedSkill("biyue")
    huamulan:addRelatedSkill("wushuang")
end
Fk:loadTranslationTable{
    ["ysch4_fuguan"] = "赴关",
    [":ysch4_fuguan"] = "你失去过【闪】或装备牌的回合结束时，可以检索牌堆至出现另一者，获得之，且可以依次使用因此亮出的【杀】。",
    ["#ysch4_fuguan-use"] = "赴关：你可以使用此【杀】",
    ["#ysch4_fuguan1"] = "【闪】",
    ["#ysch4_fuguan2"] = "装备牌",
    ["#ysch4_fuguan1#ysch4_fuguan2"] = "【闪】或装备牌",
    ["#ysch4_fuguan2#ysch4_fuguan1"] = "【闪】或装备牌",
    ["#ysch4_fuguan-prompt"] = "是否发动 赴关，检索牌堆直至出现%arg",
    ["ysch4_rongzhuang"] = "戎装",
    [":ysch4_rongzhuang"] = "锁定技，若你装备区内的牌数小于体力值，你视为拥有“闭月”的女性角色，否则你视为拥有“无双”的男性角色。",
}
local chenguinv = General:new(extension, "ysch4__chenguinv", "jin", 3, 3, General.Female)--
Fk:loadTranslationTable{
    ["ysch4__chenguinv"] = "陈归女",
    ["#ysch4__chenguinv"] = "轻拢慢捻抹复挑",
    ["designer:ysch4__chenguinv"] = "月落琴张",
    ["cv:ysch4__chenguinv"] = "佚名",
    ["illustrator:ysch4__chenguinv"] = "未知",
}
if chenguinv then
    local mingse = fk.CreateTriggerSkill{
        name = "ysch4_mingse",
        mute = true,
        events = {fk.CardUsing,fk.AfterCardsMove},
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) then
                local mark = player:getTableMark("@ysch4_mingse")
                if event == fk.CardUsing then
                    local n = 0
                    player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                        local use = e.data[1]
                        if use.from == player.id then
                        n = n + 1
                        end
                    end, Player.HistoryRound)
                    return target == player and player.room:getBanner("RoundCount") == n and table.contains(mark,"@ysch4__chenguinv1")
                else
                    if table.contains(mark,"@ysch4__chenguinv3") then
                        for _, move in ipairs(data) do
                            if move.from == player.id and move.moveReason == fk.ReasonDiscard then
                                for _, info in ipairs(move.moveInfo) do
                                    if info.fromArea == Player.Hand or info.fromArea == Player.Equip then
                                        return true
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end,
        on_cost = function (self, event, target, player, data)
            local room = player.room
            local mark = player:getTableMark("@ysch4_mingse")
            local prompt
            local cp = table.filter(room.alive_players,function (tp)
                return tp.seat == room:getBanner("RoundCount")
            end)[1]
            self.cost_data = {}
            local cards = {}
            if event == fk.CardUsing then
                cards = Card:getIdList(data.card)
                local targets , tos = {}, {}
                for _, p in ipairs(room.alive_players) do
                    if table.every(room.alive_players, function(j) return j.hp <= p.hp end) or (table.every(room.alive_players, function(j) return j.hp >= p.hp end) and p:isWounded()) then
                        table.insertIfNeed(targets,p.id)
                    end
                end
                if #targets > 0 then
                    prompt = Fk:translate(self.name,"zh_CN").."：你可以令体力值最小/最大的一名角色回复/失去1点体力"
                    if mark[2] == "@ysch4__chenguinv2" then
                        if cp and not cp.dead and #cards > 0 then
                            prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                        elseif #mark > 2 and mark[3] == "@ysch4__chenguinv4" and #room:canMoveCardInBoard() > 0 then
                            prompt = prompt.."；或点“取消”，移动场上一张牌"
                        end
                    elseif mark[2] == "@ysch4__chenguinv4" then
                        if #room:canMoveCardInBoard() > 0 then
                            prompt = prompt.."；或点“取消”，移动场上一张牌"
                        elseif #mark > 2 and mark[3] == "@ysch4__chenguinv2" and cp and not cp.dead and #cards > 0 then
                            prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                        end
                    end
                    tos = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)
                    if #tos > 0 then
                        self.cost_data.number = 1
                        self.cost_data.tos = tos
                    end
                end
            else
                for _, move in ipairs(data) do
                    if move.from == player.id and move.moveReason == fk.ReasonDiscard then
                        for _, info in ipairs(move.moveInfo) do
                            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                                table.insertIfNeed(cards,info.cardId)
                            end
                        end
                    end
                end
                prompt = Fk:translate(self.name,"zh_CN").."：你可以重铸"..tostring(room:getBanner("RoundCount")).."张手牌"
                if mark[2] == "@ysch4__chenguinv2" then
                    if cp and not cp.dead and #cards > 0 then
                        prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv4" and #room:canMoveCardInBoard() > 0 then
                        prompt = prompt.."；或点“取消”，移动场上一张牌"
                    end
                elseif mark[2] == "@ysch4__chenguinv4" then
                    if #room:canMoveCardInBoard() > 0 then
                        prompt = prompt.."；或点“取消”，移动场上一张牌"
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv2" and cp and not cp.dead and #cards > 0 then
                        prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                    end
                end
                local cards = room:askForCard(player, room:getBanner("RoundCount"), room:getBanner("RoundCount"), false, self.name, true, ".", prompt)
                if #cards > 0 then
                    self.cost_data.number = 3
                    self.cost_data.cards = cards
                end
            end
            if type(self.cost_data.number) ~= "number" then
                if mark[2] == "@ysch4__chenguinv2" then
                    if cp and not cp.dead and #Card:getIdList(data.card) > 0 then
                        self.cost_data.number = 2
                        self.cost_data.cards = cards
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv4" and #room:canMoveCardInBoard() > 0 then
                        self.cost_data.number = 4
                    end
                elseif mark[2] == "@ysch4__chenguinv4" then
                    if #room:canMoveCardInBoard() > 0 then
                        self.cost_data.number = 4
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv2" and cp and not cp.dead and #Card:getIdList(data.card) > 0 then
                        self.cost_data.number = 2
                        self.cost_data.cards = cards
                    end
                end
            end
            if type(self.cost_data.number) == "number" then return true end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            if self.cost_data.number == 1 then
                room:notifySkillInvoked(player,self.name,"defensive")
                local cp = room:getPlayerById(self.cost_data.tos[1])
                local choices = {}
                if table.every(room.alive_players, function(j) return j.hp >= cp.hp end) and cp:isWounded() then
                    table.insertIfNeed(choices,"recover")
                end
                if table.every(room.alive_players, function(j) return j.hp <= cp.hp end) then
                    table.insertIfNeed(choices,"loseHp")
                end
                local choice = room:askForChoice(player,choices,self.name,"#ysch4__chenguinv1::"..cp.id..":"..self.name)
                if choice == "recover" then
                    room:recover({who = cp,recoverBy = player,num = 1,skillName = self.name})
                else
                    room:loseHp(cp,1,self.name)
                end
            elseif self.cost_data.number == 2 then
                room:notifySkillInvoked(player,self.name,"support")
                local cp = table.filter(room.alive_players,function (tp)
                    return tp.seat == room:getBanner("RoundCount")
                end)[1]
                local cards = self.cost_data.cards
                room:obtainCard(cp,cards,true,fk.ReasonJustMove,player.id,self.name)
            elseif self.cost_data.number == 3 then
                room:notifySkillInvoked(player,self.name,"drawcard")
                local cards = self.cost_data.cards
                room:recastCard(cards, player, self.name)
            elseif self.cost_data.number == 4 then
                room:notifySkillInvoked(player,self.name,"control")
                local tars = room:askForChooseToMoveCardInBoard(player, "鸣瑟：移动场上一张牌", self.name, false)
                if #tars == 2 then
                    room:askForMoveCardInBoard(player, room:getPlayerById(tars[1]), room:getPlayerById(tars[2]), self.name)
                end
            end
        end,
        dynamic_desc = function (self, player, lang)
            local str = ""
            local intro = {
                ["@ysch4__chenguinv1"] = "①每轮你使用第X张牌时，可以令体力值最小/最大的一名角色回复/失去1点体力",
                ["@ysch4__chenguinv2"] = "②若你未发动前述效果，则令座次为X的角色获得此牌",
                ["@ysch4__chenguinv3"] = "③当你的牌被弃置后，你可以重铸X张手牌",
                ["@ysch4__chenguinv4"] = "④若你未发动前述效果，则移动场上一张牌",
            }
            local mark = player:getTableMark("@ysch4_mingse")
            if #mark > 0 then
                for index, value in ipairs(mark) do
                    str = str .. intro[value]
                    if index == #mark then
                        str = str .. "。"
                    else
                        str = str .. "；"
                    end
                end
            else
                str = "①每轮你使用第X张牌时，可以令体力值最小/最大的一名角色回复/失去1点体力；②若你未发动前述效果，则令座次为X的角色获得此牌。"
            end
            return str .. "（X为游戏轮数）"
        end,
        on_acquire = function (self, player, is_start)
            player.room:setPlayerMark(player, "@ysch4_mingse", {"@ysch4__chenguinv1", "@ysch4__chenguinv2"})
        end,
        on_lose = function (self, player, is_death)
            player.room:setPlayerMark(player, "@ysch4_mingse", 0)
        end,
    }
    chenguinv:addSkill(mingse)
    local heyin = fk.CreateTriggerSkill{
        name = "ysch4_heyin",
        mute = true,
        events = {fk.CardUsing,fk.AfterCardsMove},
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) then
                local mark = player:getTableMark("@ysch4_heyin")
                if event == fk.CardUsing then
                    local n = 0
                    player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
                        local use = e.data[1]
                        if use.from == player.id then
                        n = n + 1
                        end
                    end, Player.HistoryRound)
                    return target == player and player.room:getBanner("RoundCount") == n and table.contains(mark,"@ysch4__chenguinv1")
                else
                    if table.contains(mark,"@ysch4__chenguinv3") then
                        for _, move in ipairs(data) do
                            if move.from == player.id and move.moveReason == fk.ReasonDiscard then
                                for _, info in ipairs(move.moveInfo) do
                                    if info.fromArea == Player.Hand or info.fromArea == Player.Equip then
                                        return true
                                    end
                                end
                            end
                        end
                    end
                end
            end
        end,
        on_cost = function (self, event, target, player, data)
            local room = player.room
            local mark = player:getTableMark("@ysch4_heyin")
            local prompt
            local cp = table.filter(room.alive_players,function (tp)
                return tp.seat == room:getBanner("RoundCount")
            end)[1]
            self.cost_data = {}
            local cards = {}
            if event == fk.CardUsing then
                cards = Card:getIdList(data.card)
                local targets , tos = {}, {}
                for _, p in ipairs(room.alive_players) do
                    if table.every(room.alive_players, function(j) return j.hp <= p.hp end) or (table.every(room.alive_players, function(j) return j.hp >= p.hp end) and p:isWounded()) then
                        table.insertIfNeed(targets,p.id)
                    end
                end
                if #targets > 0 then
                    prompt = Fk:translate(self.name,"zh_CN").."：你可以令体力值最小/最大的一名角色回复/失去1点体力"
                    if mark[2] == "@ysch4__chenguinv2" then
                        if cp and not cp.dead and #cards > 0 then
                            prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                        elseif #mark > 2 and mark[3] == "@ysch4__chenguinv4" and #room:canMoveCardInBoard() > 0 then
                            prompt = prompt.."；或点“取消”，移动场上一张牌"
                        end
                    elseif mark[2] == "@ysch4__chenguinv4" then
                        if #room:canMoveCardInBoard() > 0 then
                            prompt = prompt.."；或点“取消”，移动场上一张牌"
                        elseif #mark > 2 and mark[3] == "@ysch4__chenguinv2" and cp and not cp.dead and #cards > 0 then
                            prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                        end
                    end
                    tos = room:askForChoosePlayers(player, targets, 1, 1, prompt, self.name, true)
                    if #tos > 0 then
                        self.cost_data.number = 1
                        self.cost_data.tos = tos
                    end
                end
            else
                for _, move in ipairs(data) do
                    if move.from == player.id and move.moveReason == fk.ReasonDiscard then
                        for _, info in ipairs(move.moveInfo) do
                            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                                table.insertIfNeed(cards,info.cardId)
                            end
                        end
                    end
                end
                prompt = Fk:translate(self.name,"zh_CN").."：你可以重铸"..tostring(room:getBanner("RoundCount")).."张手牌"
                if mark[2] == "@ysch4__chenguinv2" then
                    if cp and not cp.dead and #cards > 0 then
                        prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv4" and #room:canMoveCardInBoard() > 0 then
                        prompt = prompt.."；或点“取消”，移动场上一张牌"
                    end
                elseif mark[2] == "@ysch4__chenguinv4" then
                    if #room:canMoveCardInBoard() > 0 then
                        prompt = prompt.."；或点“取消”，移动场上一张牌"
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv2" and cp and not cp.dead and #cards > 0 then
                        prompt = prompt.."；或点“取消”，令座次为"..tostring(room:getBanner("RoundCount")).."的角色获得此牌"
                    end
                end
                local cards = room:askForCard(player, room:getBanner("RoundCount"), room:getBanner("RoundCount"), false, self.name, true, ".", prompt)
                if #cards > 0 then
                    self.cost_data.number = 3
                    self.cost_data.cards = cards
                end
            end
            if type(self.cost_data.number) ~= "number" then
                if mark[2] == "@ysch4__chenguinv2" then
                    if cp and not cp.dead and #Card:getIdList(data.card) > 0 then
                        self.cost_data.number = 2
                        self.cost_data.cards = cards
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv4" and #room:canMoveCardInBoard() > 0 then
                        self.cost_data.number = 4
                    end
                elseif mark[2] == "@ysch4__chenguinv4" then
                    if #room:canMoveCardInBoard() > 0 then
                        self.cost_data.number = 4
                    elseif #mark > 2 and mark[3] == "@ysch4__chenguinv2" and cp and not cp.dead and #Card:getIdList(data.card) > 0 then
                        self.cost_data.number = 2
                        self.cost_data.cards = cards
                    end
                end
            end
            if type(self.cost_data.number) == "number" then return true end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            if self.cost_data.number == 1 then
                room:notifySkillInvoked(player,self.name,"defensive")
                local cp = room:getPlayerById(self.cost_data.tos[1])
                local choices = {}
                if table.every(room.alive_players, function(j) return j.hp >= cp.hp end) and cp:isWounded() then
                    table.insertIfNeed(choices,"recover")
                end
                if table.every(room.alive_players, function(j) return j.hp <= cp.hp end) then
                    table.insertIfNeed(choices,"loseHp")
                end
                local choice = room:askForChoice(player,choices,self.name,"#ysch4__chenguinv1::"..cp.id..":"..self.name)
                if choice == "recover" then
                    room:recover({who = cp,recoverBy = player,num = 1,skillName = self.name})
                else
                    room:loseHp(cp,1,self.name)
                end
            elseif self.cost_data.number == 2 then
                room:notifySkillInvoked(player,self.name,"support")
                local cp = table.filter(room.alive_players,function (tp)
                    return tp.seat == room:getBanner("RoundCount")
                end)[1]
                local cards = self.cost_data.cards
                room:obtainCard(cp,cards,true,fk.ReasonJustMove,player.id,self.name)
            elseif self.cost_data.number == 3 then
                room:notifySkillInvoked(player,self.name,"drawcard")
                local cards = self.cost_data.cards
                room:recastCard(cards, player, self.name)
            elseif self.cost_data.number == 4 then
                room:notifySkillInvoked(player,self.name,"control")
                local tars = room:askForChooseToMoveCardInBoard(player, "鸣瑟：移动场上一张牌", self.name, false)
                if #tars == 2 then
                    room:askForMoveCardInBoard(player, room:getPlayerById(tars[1]), room:getPlayerById(tars[2]), self.name)
                end
            end
        end,
        dynamic_desc = function (self, player, lang)
            local str = ""
            local intro = {
                ["@ysch4__chenguinv1"] = "①每轮你使用第X张牌时，可以令体力值最小/最大的一名角色回复/失去1点体力",
                ["@ysch4__chenguinv2"] = "②若你未发动前述效果，则令座次为X的角色获得此牌",
                ["@ysch4__chenguinv3"] = "③当你的牌被弃置后，你可以重铸X张手牌",
                ["@ysch4__chenguinv4"] = "④若你未发动前述效果，则移动场上一张牌",
            }
            local mark = player:getTableMark("@ysch4_heyin")
            if #mark > 0 then
                for index, value in ipairs(mark) do
                    str = str .. intro[value]
                    if index == #mark then
                        str = str .. "。"
                    else
                        str = str .. "；"
                    end
                end
            else
                str = "①每轮你使用第X张牌时，可以令体力值最小/最大的一名角色回复/失去1点体力；②若你未发动前述效果，则令座次为X的角色获得此牌。"
            end
            if not player:hasSkill("ysch4_mingse") then
                str = str .. "（X为游戏轮数）"
            end
            return str
        end,
        on_acquire = function (self, player, is_start)
            player.room:setPlayerMark(player, "@ysch4_heyin", {"@ysch4__chenguinv3", "@ysch4__chenguinv4"})
        end,
        on_lose = function (self, player, is_death)
            player.room:setPlayerMark(player, "@ysch4_heyin", 0)
        end,
    }
    chenguinv:addSkill(heyin)
    local huarong = fk.CreateTriggerSkill{
        name = "ysch4_huarong",
        mute = true,
        dynamic_desc = function (self, player, lang)
            local str = "每轮结束时，你可以将手牌调整至X"
            if not player:hasSkill("ysch4_mingse") and not player:hasSkill("ysch4_heyin") then
                str = str .. "。（X为游戏轮数）"
            elseif player:hasSkill("ysch4_mingse") and player:hasSkill("ysch4_heyin") then
                str = str .. "；结算后若你因此弃牌，将上述奇数项调换；若你因此摸牌，将上述将一个偶数项移动至一项后。"
            end
            return str
        end,
        events = {fk.RoundEnd},
        can_trigger = function (self, event, target, player, data)
            return player:hasSkill(self.name) and player:getHandcardNum() ~= player.room:getBanner("RoundCount")
        end,
        on_cost = function (self, event, target, player, data)
            if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_huarong-invoke:::"..player.room:getBanner("RoundCount")) then
                return true
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local x = player:getHandcardNum() - room:getBanner("RoundCount")
            local mark1, mark2 = player:getTableMark("@ysch4_mingse"), player:getTableMark("@ysch4_heyin")
            if x > 0 then
                room:notifySkillInvoked(player,self.name,"negative")
                room:askForDiscard(player,x,x,false,self.name,false,nil,"#ysch4_huarong-discard:::"..room:getBanner("RoundCount"))
                if #mark1 > 0 and #mark2 > 0 then
                    local first, second = mark1[1], mark2[1]
                    mark2[1] = first
                    mark1[1] = second
                    room:setPlayerMark(player,"@ysch4_mingse",mark1)
                    room:setPlayerMark(player,"@ysch4_heyin", mark2)
                end
            elseif x < 0 then
                room:notifySkillInvoked(player,self.name,"drawcard")
                player:drawCards(-x,self.name)
                if #mark1 > 0 and #mark2 > 0 then
                    local function indexOf(array,value)
                        for i = 1, #array, 1 do
                            if array[i] == value then
                                return i
                            end
                        end
                        return nil
                    end
                    local choice = room:askForChoice(player,{"@ysch4__chenguinv2","@ysch4__chenguinv4"},self.name,"#ysch4_huarong-choose")
                    local choices, all_choices = {"@ysch4__chenguinv1","@ysch4__chenguinv2","@ysch4__chenguinv3","@ysch4__chenguinv4"}, {"@ysch4__chenguinv1","@ysch4__chenguinv2","@ysch4__chenguinv3","@ysch4__chenguinv4"}
                    local num1, num2 = indexOf(mark1, choice), indexOf(mark2, choice)
                    table.removeOne(choices, choice)
                    if num1 and num1 >1 then table.removeOne(choices, mark1[num1-1]) end
                    if num2 and num2 >1 then table.removeOne(choices, mark2[num2-1]) end
                    local add = room:askForChoice(player,choices,self.name,"#ysch4_huarong-add:::"..choice,false,all_choices)
                    if num1 then table.removeOne(mark1,choice) end
                    if num2 then table.removeOne(mark2,choice) end
                    if indexOf(mark1, add) then
                        local num = indexOf(mark1, add)
                        table.insert(mark1,num+1,choice)
                    else
                        local num = indexOf(mark2, add)
                        table.insert(mark2,num+1,choice)
                    end
                    room:setPlayerMark(player,"@ysch4_mingse",mark1)
                    room:setPlayerMark(player,"@ysch4_heyin", mark2)
                end
            end
        end,
    }
    chenguinv:addSkill(huarong)
end
Fk:loadTranslationTable{
    ["ysch4_mingse"] = "鸣瑟",
    [":ysch4_mingse"] = "①每轮你使用第X张牌时，可以令体力值最小/最大的一名角色回复/失去1点体力；②若你未发动前述效果，则令座次为X的角色获得此牌。（X为游戏轮数）",
    ["@ysch4_mingse"] = "鸣瑟",
    ["@ysch4__chenguinv1"] = "①",
    ["#ysch4__chenguinv1"] = "%arg：你可以令%dest回复或失去1点体力",
    ["@ysch4__chenguinv2"] = "②",
    ["ysch4_heyin"] = "和音",
    [":ysch4_heyin"] = "③当你的牌被弃置后，你可以重铸X张手牌；④若你未发动前述效果，则移动场上一张牌。",
    ["@ysch4_heyin"] = "和音",
    ["@ysch4__chenguinv3"] = "③",
    ["@ysch4__chenguinv4"] = "④",
    ["ysch4_huarong"] = "花容",
    [":ysch4_huarong"] = "每轮结束时，你可以将手牌调整至X；结算后若你因此弃牌，将上述奇数项调换；若你因此摸牌，将上述将一个偶数项移动至一项后。",
    ["#ysch4_huarong-invoke"] = "是否发动 花容，将手牌调整至 %arg",
    ["#ysch4_huarong-discard"] = "花容：将手牌调整至 %arg",
    ["#ysch4_huarong-choose"] = "花容：请选择你要移动的偶数项",
    ["#ysch4_huarong-add"] = "花容：将%arg项移至一项后",
}
local caohong = General:new(extension, "ysch4__caohong", "wei", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__caohong"] = "曹洪",
    ["#ysch4__caohong"] = "福将良驹",
    ["designer:ysch4__caohong"] = "幽蝶化烬",
    ["cv:ysch4__caohong"] = "佚名",
    ["illustrator:ysch4__caohong"] = "李秀森",
}
if caohong then
    local yuanhu = fk.CreateTriggerSkill{
        name = "ysch4_yuanhu",
        events = {fk.Damaged},
        anim_type = "support",
        can_trigger = function (self, event, target, player, data)
            return player:hasSkill(self.name) and not target.dead and target.phase == Player.NotActive and not table.contains(player:getTableMark("@[player]ysch4_yuanhu-round"),target.id)
        end,
        on_cost = function (self, event, target, player, data)
            if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_yuanhu-prompt::"..target.id) then
                return true
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            target:drawCards(1,self.name)
            if not target.dead then
                local current = table.find(player.room.alive_players, function(p) return p.phase ~= Player.NotActive end)
                local targets = {target.id}
                if current then
                    table.insertIfNeed(targets,current.id)
                end
                local use = U.askForPlayCard(room, target, nil, nil, self.name,
                "#ysch4_yuanhu-use", {bypass_times = true, extraUse = true, bypass_distances = true, exclusive_targets = targets},true)
                if use then
                    room:useCard(use)
                else
                    room:addTableMark(player, "@[player]ysch4_yuanhu-round", target.id)
                end
            end
        end,
    }
    caohong:addSkill(yuanhu)
    local heyi = fk.CreateTriggerSkill{
        name = "ysch4_heyi",
        events = {fk.CardUsing},
        can_trigger = function (self, event, target, player, data)
            return player:hasSkill(self.name) and target.phase == Player.NotActive and data.card.type == Card.TypeBasic
        end,
        on_cost = function (self, event, target, player, data)
            local room = player.room
            local cards = room:askForDiscard(player,1,1,true,"ysch4_heyi_zhuzhan",true,".|.|.|.|.|"..data.card:getTypeString(),"#ysch4_heyi-invoke:"..target.id.."::"..data.card:getTypeString()..":"..data.card:toLogString(),true)
            if #cards > 0 then
                self.cost_data = cards
                return tonumber
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            room:throwCard(self.cost_data, "variation", player, player)
            data.extra_data = data.extra_data or {}
            if data.card.is_damage_card then
                data.additionalDamage = (data.additionalDamage or 0) + 1
            elseif data.card.name == "peach" then
                data.additionalRecover = (data.additionalRecover or 0) + 1
            elseif data.card.name == "analeptic" then
                if data.extra_data and data.extra_data.analepticRecover then
                    data.additionalRecover = (data.additionalRecover or 0) + 1
                else
                    data.extra_data.additionalDrank = (data.extra_data.additionalDrank or 0) + 1
                end
            end
            data.extra_data.ysch4_heyi = data.extra_data.ysch4_heyi or {}
            table.insertIfNeed(data.extra_data.ysch4_heyi,target.id)
        end,

        refresh_events = {fk.CardUseFinished,fk.PreHpRecover, fk.PreHpLost, fk.DamageInflicted},
        can_refresh = function (self, event, target, player, data)
            if event == fk.CardUseFinished then
                return data.extra_data and data.extra_data.ysch4_heyi
            else
                return target:getMark("@@xiaobai__yujie-turn") ~= 0
            end
        end,
        on_refresh = function (self, event, target, player, data)
            local room = player.room
            if event == fk.CardUseFinished then
                for _, id in ipairs(data.extra_data.ysch4_heyi) do
                    local cp = room:getPlayerById(id)
                    if not cp.dead then
                        room:setPlayerMark(cp,"@@ysch4_heyi-turn",1)
                    end
                end
            elseif event == fk.DamageInflicted then
                data.damage = 0
            else
                data.num = 0
            end
        end,
    }
    local heyi_prohibit = fk.CreateProhibitSkill{
        name = "#ysch4_heyi_prohibit",
        prohibit_use = function(self, player, card)
        return player:getMark("@@ysch4_heyi-turn") ~= 0
        end,
        is_prohibited = function(self, from, to, card)
        return to:getMark("@@ysch4_heyi-turn") ~= 0
        end,
    }
    heyi:addRelatedSkill(heyi_prohibit)

    --[[local heyi_invalidity = fk.CreateInvaliditySkill {
        name = "#ysch4_heyi_invalidity",
        invalidity_func = function(self, from, skill)
        return from:getMark("@@ysch4_heyi-turn") > 0 and skill:isPlayerSkill(from)
        end
    }
    heyi:addRelatedSkill(heyi_invalidity)]]--
    caohong:addSkill(heyi)
end
Fk:loadTranslationTable{
    ["ysch4_yuanhu"] = "援护",
    [":ysch4_yuanhu"] = "一名角色于其回合外受到伤害后，你可以令其摸一张牌，然后其选择一项：仅对其或当前回合角色使用一张牌（无距离次数限制）；或令本技能本轮对其失效。",
    ["#ysch4_yuanhu-prompt"] = "是否发动 援护，令%dest摸一张牌",
    ["#ysch4_yuanhu-use"] = "援护：对你或当前回合角色使用一张牌或令此技能本轮对你失效",
    ["@[player]ysch4_yuanhu-round"] = "援护失效",
    ["ysch4_heyi"] = "鹤翼",
    [":ysch4_heyi"] = "一名角色于其回合外使用基本牌时，你可以助战→令此牌牌面数值+1。若如此做，此牌结算后将其移出游戏直至本回合结束。",
    ["ysch4_heyi_zhuzhan"] = "鹤翼助战",
    ["@@ysch4_heyi-turn"] = "移除游戏",
    ["#ysch4_heyi-invoke"] = "是否发动 鹤翼，弃置一张%arg，助战%src使用的%arg2牌面数值+1",
}
local yuwenhuaji = General:new(extension, "ysch4__yuwenhuaji", "sui", 5, 5, General.Male)--
Fk:loadTranslationTable{
    ["sui"] = "隋",
    ["ysch4__yuwenhuaji"] = "宇文化及",
    ["#ysch4__yuwenhuaji"] = "鲸波覆隋",
    ["designer:ysch4__yuwenhuaji"] = "昆世",
    ["cv:ysch4__yuwenhuaji"] = "佚名",
    ["illustrator:ysch4__yuwenhuaji"] = "未知",
}
if yuwenhuaji then
    local maoyue = fk.CreateTriggerSkill{
        name = "ysch4_maoyue",
        events = {fk.GameStart,fk.RoundStart,fk.AfterSkillEffect},
        mute = true,
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) then
                if event == fk.GameStart then
                    return true
                else
                    local RoundEnd = tonumber(player:getMark("@ysch4_maoyue"))
                    local num = math.abs(player.room:getBanner("RoundCount")-RoundEnd)
                    return player:getMark("@ysch4_maoyue") ~= 0 and num ~= player:getMark(self.name)
                end
            end
        end,
        on_cost = function (self, event, target, player, data)
            if event == fk.GameStart then
                local minNum = 1
                while true do
                    local choices, all_choices = {}, {}
                    for i = minNum, minNum + 99, 1 do
                        table.insert(choices,tostring(i))
                        table.insert(all_choices,tostring(i))
                    end
                    if minNum > 1 then
                        table.insert(choices,"#ysch4_maoyue-previous")
                    end
                    table.insert(all_choices,"#ysch4_maoyue-previous")
                    if minNum > 1000 then
                        table.insert(choices,"#ysch4_maoyue-previous10")
                    end
                    table.insert(all_choices,"#ysch4_maoyue-previous10")
                    table.insert(choices,"#ysch4_maoyue-next10")
                    table.insert(all_choices,"#ysch4_maoyue-next10")
                    table.insert(choices,"#ysch4_maoyue-next")
                    table.insert(all_choices,"#ysch4_maoyue-next")
                    local choice = player.room:askForChoice(player,choices,self.name,"#ysch4_maoyue-prompt",false,all_choices)
                    if not string.find(choice,"#ysch4_maoyue") then
                        self.cost_data = choice
                        return true
                    elseif choice == "#ysch4_maoyue-previous" then
                        minNum = minNum - 100
                    elseif choice == "#ysch4_maoyue-previous10" then
                        minNum = minNum - 1000
                    elseif choice == "#ysch4_maoyue-next" then
                        minNum = minNum + 100
                    else
                        minNum = minNum + 1000
                    end
                end
            else
                local RoundEnd = tonumber(player:getMark("@ysch4_maoyue"))
                local num = math.abs(player.room:getBanner("RoundCount")-RoundEnd)
                if num - player:getMark(self.name) > 0 then
                    self.cost_data = player.room:askForChoice(player, {"loseMaxHp"}, self.name)
                end
                return true
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            if event == fk.GameStart then
                room:notifySkillInvoked(player,self.name,"big")
                room:setPlayerMark(player,"@ysch4_maoyue",self.cost_data)
                local num = math.abs(tonumber(self.cost_data) - room:getBanner("RoundCount"))
                room:setPlayerMark(player,self.name,num)
                player:chat("游戏将在第"..self.cost_data.."轮结束")
                if self.cost_data == "1" then
                    local subtype_string_table = {
                        [Card.SubtypeArmor] = "armor",
                        [Card.SubtypeWeapon] = "weapon",
                        [Card.SubtypeTreasure] = "treasure",
                        [Card.SubtypeDelayedTrick] = "delayed_trick",
                        [Card.SubtypeDefensiveRide] = "defensive_ride",
                        [Card.SubtypeOffensiveRide] = "offensive_ride",
                    }
                    for _, slot in ipairs(player:getAvailableEquipSlots()) do
                        if player.dead then return end
                        local type = Util.convertSubtypeAndEquipSlot(slot)
                        if #player:getEquipments(type) < #player:getAvailableEquipSlots(type) then
                            local id = room:getCardsFromPileByRule(".|.|.|.|.|"..subtype_string_table[type], 1, "allPiles")[1]
                            if id then
                                room:useCard({
                                    from = player.id,
                                    tos = {{player.id}},
                                    card = Fk:getCardById(id),
                                })
                            end
                        end
                    end
                end
            else
                local RoundEnd = player:getMark("@ysch4_maoyue")
                local num = math.abs(room:getBanner("RoundCount")-RoundEnd)
                local mark = player:getMark(self.name)
                room:setPlayerMark(player,self.name,num)
                if num - mark < 0 then
                    room:notifySkillInvoked(player,self.name,"offensive")
                    room:addPlayerMark(player,"ysch4_maoyue_sha",1)
                end
                if num - mark > 0 then
                    room:notifySkillInvoked(player,self.name,"negative")
                    if self.cost_data == "loseMaxHp" then
                        room:changeMaxHp(player,-1)
                    else
                        room:loseHp(player, 1, self.name)
                    end
                end
                if num == 0 then
                    if num - mark == 0 then
                        room:notifySkillInvoked(player,self.name,"big")
                    end
                    local subtype_string_table = {
                        [Card.SubtypeArmor] = "armor",
                        [Card.SubtypeWeapon] = "weapon",
                        [Card.SubtypeTreasure] = "treasure",
                        [Card.SubtypeDelayedTrick] = "delayed_trick",
                        [Card.SubtypeDefensiveRide] = "defensive_ride",
                        [Card.SubtypeOffensiveRide] = "offensive_ride",
                    }
                    for _, slot in ipairs(player:getAvailableEquipSlots()) do
                        if player.dead then return end
                        local type = Util.convertSubtypeAndEquipSlot(slot)
                        if #player:getEquipments(type) < #player:getAvailableEquipSlots(type) then
                            local id = room:getCardsFromPileByRule(".|.|.|.|.|"..subtype_string_table[type], 1, "allPiles")[1]
                            if id then
                                room:useCard({
                                    from = player.id,
                                    tos = {{player.id}},
                                    card = Fk:getCardById(id),
                                })
                            end
                        end
                    end
                end
            end
        end,
    }
    local maoyue_targetmod = fk.CreateTargetModSkill{
        name = "#ysch4_maoyue_targetmod",
        main_skill = maoyue,
        residue_func = function(self, player, skill, scope)
            if player:hasSkill(maoyue) and skill.trueName == "slash_skill" and scope == Player.HistoryPhase then
                return player:getMark("ysch4_maoyue_sha")
            end
        end,
    }
    maoyue:addRelatedSkill(maoyue_targetmod)
    yuwenhuaji:addSkill(maoyue)
    local jianxiao = fk.CreateViewAsSkill{
        name = "ysch4_jianxiao",
        pattern = "slash,jink",
        interaction = function()
            local names = {}
            for _, name in ipairs({"slash","jink"}) do
                if (name == "slash" and tonumber(Self:getMark("@ysch4_maoyue")) > 0) or name == "jink" then
                    local card = Fk:cloneCard(name)
                    if (Fk.currentResponsePattern == nil and Self:canUse(card)) or
                        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
                        table.insertIfNeed(names, card.name)
                    end
                end
            end
            if #names == 0 then return end
            return U.CardNameBox {choices = names}
        end,
        card_filter = Util.FalseFunc,
        view_as = function(self)
            if not self.interaction.data then return end
            local card = Fk:cloneCard(self.interaction.data)
            card.skillName = self.name
            return card
        end,
        before_use = function (self, player, use)
            local num = tonumber(player:getMark("@ysch4_maoyue"))
            if use.card.trueName == "slash" then
                player.room:setPlayerMark(player,"@ysch4_maoyue",tostring(num-1))
                player:chat("游戏将提前一轮结束")
            else
                player.room:setPlayerMark(player,"@ysch4_maoyue",tostring(num+1))
                player:chat("游戏将推迟一轮结束")
            end
        end,
        after_use = function (self, player, use)
            if player.room:getBanner("RoundCount") >= tonumber(player:getMark("@ysch4_maoyue")) then
                U.askForUseVirtualCard(player.room,player,"ex_nihilo",nil,self.name,"#ysch4_jianxiao-use")
            end
        end,
        enabled_at_play = function(self, player)
            if player:getMark("@ysch4_maoyue") == 0 or player:usedSkillTimes(self.name, Player.HistoryRound) > 0 then return end
            return tonumber(player:getMark("@ysch4_maoyue")) > 0
        end,
        enabled_at_response = function(self, player, response)
            if response or Fk.currentResponsePattern == nil or player:getMark("@ysch4_maoyue") == 0 or player:usedSkillTimes(self.name, Player.HistoryRound) > 0 then return end
            for _, name in ipairs({"slash", "jink"}) do
                if (name == "slash" and tonumber(player:getMark("@ysch4_maoyue")) > 0) or name == "jink" then
                    local card = Fk:cloneCard(name)
                    if Exppattern:Parse(Fk.currentResponsePattern):match(card) then
                        return true
                    end
                end
            end
        end,
    }
    yuwenhuaji:addSkill(jianxiao)
    local fanfu = fk.CreateTriggerSkill{name = "ysch4_fanfu$",}
    yuwenhuaji:addSkill(fanfu)
end
Fk:loadTranslationTable{
    ["ysch4_maoyue"] = "旄钺",
    [":ysch4_maoyue"] = "游戏开始时，你声明本局游戏结束的轮次。你的出【杀】次数随接近而+1，你的体力上限随远离而-1，你的装备区随到达而填满。",
    ["@ysch4_maoyue"] = "旄钺",
    ["#ysch4_maoyue-previous"] = "上一页",
    ["#ysch4_maoyue-previous10"] = "前十页",
    ["#ysch4_maoyue-next10"] = "后十页",
    ["#ysch4_maoyue-next"] = "下一页",
    ["#ysch4_maoyue-hp"] = "体力",
    ["#ysch4_maoyue-maxHp"] = "体力上限",
    ["ysch4_jianxiao"] = "僭枭",
    [":ysch4_jianxiao"] = "轮次技，你可以令〖旄钺〗中所声明的轮次提前/推迟到来一轮以视为使用【杀】/【闪】。若到达过，你可以追加一张【无中生有】。",
    ["#ysch4_jianxiao-use"] = "僭枭：你可以视为使用【无中生有】",
    ["ysch4_fanfu"] = "翻覆",
    [":ysch4_fanfu"] = "主公技。",
}
local lataen = General:new(extension, "ysch4__lataen", "god", 4, 7, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__lataen"] = "拉塔恩",
    ["#ysch4__lataen"] = "约定之王",
    ["designer:ysch4__lataen"] = "伶",
    ["cv:ysch4__lataen"] = "佚名",
    ["illustrator:ysch4__lataen"] = "未知",
}
if lataen then
    local juewanggongshi = fk.CreateActiveSkill{
        name = "ysch4_juewanggongshi",
        max_card_num = 1,
        target_num = 1,
        anim_type = "offensive",
        card_filter = function(self, to_select, selected)
            return Fk:getCardById(to_select).trueName == "slash" and not Self:prohibitDiscard(Fk:getCardById(to_select))
        end,
        target_filter = function(self, to_select, selected, selected_cards)
            return #selected == 0 and to_select ~= Self.id and not table.contains(Self:getTableMark("ysch4_juewanggongshi-turn"), to_select)
        end,
        times = function(self)
            return Self.phase == Player.Play and 3 - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
        end,
        can_use = function (self, player)
            return player:usedSkillTimes(self.name, Player.HistoryPhase) < 3
        end,
        on_use = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            local target = room:getPlayerById(effect.tos[1])
            local num = Card:strToNumber(player:getMark("@ysch4_juewanggongshi"))
            local nums = {}
            if num > 2 then
                for i = 2, num - 1, 1 do
                    table.insertIfNeed(nums,i)
                end
            end
            if #effect.cards > 0 then
                room:throwCard(effect.cards, self.name, player)
            else
                room:changeMaxHp(player,-1)
            end
            p(tostring(Exppattern{number = nums}))
            local cards = room:askForCard(target,1,1,true,self.name,true,tostring(Exppattern{number = nums}),"#ysch4_juewanggongshi-discard::"..player.id..":"..Card:getNumberStr(num))
            if #cards > 0 then
                num = Fk:getCardById(cards[1]).number - 1
                room:setPlayerMark(player,"@ysch4_juewanggongshi",Card:getNumberStr(num))
                room:obtainCard(player,cards,false,fk.ReasonGive,target.id,self.name)
            else
                room:setPlayerMark(player,"@ysch4_juewanggongshi",Card:getNumberStr(13))
                room:addTableMark(player, "ysch4_juewanggongshi-turn", target.id)
                room:damage{
                    from = player,
                    to = target,
                    damage = 2,
                    skillName = self.name,
                }
            end
        end,
        dynamic_desc = function (self, player, lang)
            local str = "出牌阶段限三次，你可以弃置一张【杀】或减1点体力上限，令一名其他角色选择：1.交给你一张点数在A~〖"
            str = str .. Card:strToNumber(player:getMark("@ysch4_juewanggongshi"))
            return str.."〗之间的牌，然后〖 〗内点数改为此牌点数-1。2.你对其造成2点伤害并重置〖 〗内点数，然后本回合不能再对其发动此技能。"
        end,
        on_acquire = function (self, player, is_start)
            player.room:setPlayerMark(player,"@ysch4_juewanggongshi",Card:getNumberStr(13))
        end,
        on_lose = function (self, player, is_death)
            player.room:setPlayerMark(player,"@ysch4_juewanggongshi",0)
        end,
    }
    lataen:addSkill(juewanggongshi)
    local wenroulvfa = fk.CreateTriggerSkill{
        name = "ysch4_wenroulvfa",
        anim_type = "control",
        events = {fk.TurnStart},
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) and player == target then
                local enemies = {}
                player.room.logic:getActualDamageEvents(999, function(e)
                    local damageData = e.data[1]
                    if damageData.from and not damageData.from.dead and player:canPindian(damageData.from) and damageData.to == player then
                        table.insertIfNeed(enemies, damageData.from.id)
                    end
                    return false
                end,Player.HistoryGame)
                return #enemies > 0
            end
        end,
        on_cost = function (self, event, target, player, data)
            local room = player.room
            local enemies = {}
            room.logic:getActualDamageEvents(999, function(e)
                local damageData = e.data[1]
                if damageData.from and not damageData.from.dead and player:canPindian(damageData.from) and damageData.to == player then
                    table.insertIfNeed(enemies, damageData.from.id)
                end
                return false
            end,Player.HistoryGame)
            local tos = room:askForChoosePlayers(player,enemies,1,1,"#ysch4_wenroulvfa",self.name)
            if #tos > 0 then
                self.cost_data = tos[1]
                return true
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local to = room:getPlayerById(self.cost_data)
            local pindian = player:pindian({to}, self.name)
            local winner = pindian.results[to.id].winner
            if winner ~= player then
                player:drawCards(3,self.name)
            end
        end,
    }
    lataen:addSkill(wenroulvfa)
end
Fk:loadTranslationTable{
    ["ysch4_juewanggongshi"] = "绝望攻势",
    [":ysch4_juewanggongshi"] = "出牌阶段限三次，你可以弃置一张【杀】或减1点体力上限，令一名其他角色选择：1.交给你一张点数在A~〖K〗之间的牌，然后〖 〗内点数改为此牌点数-1。2.你对其造成2点伤害并重置〖 〗内点数，然后本回合不能再对其发动此技能。",
    ["@ysch4_juewanggongshi"] = "绝望攻势",
    ["#ysch4_juewanggongshi-discard"] = "绝望攻势：交给 %dest 一种点数在A~%arg之间的牌，否则其对你造成2点伤害",
    ["ysch4_wenroulvfa"] = "温柔律法",
    [":ysch4_wenroulvfa"] = "回合开始时，你可以与一名对你造成过伤害的其他角色拼点，若你没赢，你摸三张牌。"..
    "<br><br> <font color = '#a40000'>“哥哥，我一定会成为神袛。如果我实现约定，请成为我的王……我想打造一个温柔的世界。”",
    ["#ysch4_wenroulvfa"] = "是否发动 温柔律法，与一名其他角色拼点，若你没赢，你摸三张牌",
}
local liuba = General:new(extension, "ysch4__liuba", "shu", 3, 3, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__liuba"] = "刘巴",
    ["#ysch4__liuba"] = "情尚之节",
    ["designer:ysch4__liuba"] = "牧孖",
    ["cv:ysch4__liuba"] = "佚名",
    ["illustrator:ysch4__liuba"] = "未知",
}
if liuba then
    local zhubi = fk.CreateActiveSkill{
        name = "ysch4_zhubi",
        min_card_num = 1,
        target_num = 0,
        target_filter = Util.FalseFunc,
        anim_type = "drawcard",
        card_filter = function (self, to_select, selected, player)
            local n = Fk:getCardById(to_select).number
            for _, id in ipairs(selected) do
            n = n + Fk:getCardById(id).number
            end
            return n <= 12
        end,
        feasible = function (self, selected, selected_cards)
            local num = 0
            for _, id in ipairs(selected_cards) do
                num = num + Fk:getCardById(id).number
            end
            return table.contains({4,8,12},num)
        end,
        prompt = "#ysch4_zhubi",
        on_use = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            room:recastCard(effect.cards, player, self.name)
            local num = player:getMark("@ysch4_zhubi-turn")
            room:addPlayerMark(player,"@ysch4_zhubi-turn",#effect.cards)
            for _, v in ipairs({4,8,12}) do
                if num <= v and v < (num+#effect.cards) then
                    room:addPlayerMark(player,"@ysch4_tongdu-round",1)
                end
            end
        end,
    }
    liuba:addSkill(zhubi)
    local tongdu_foresightSkill = fk.CreateActiveSkill{
        name = "ysch4_tongdu_foresight_skill",
        mod_target_filter = Util.TrueFunc,
        can_use = function(self, player, card)
            return Util.SelfCanUse(self, player, card)
        end,
        on_use = function(self, room, cardUseEvent)
            if not cardUseEvent.tos or #TargetGroup:getRealTargets(cardUseEvent.tos) == 0 then
            cardUseEvent.tos = {{cardUseEvent.from}}
            end
        end,
        anim_type = "drawcard",
        on_effect = function(self, room, effect)
            local to = room:getPlayerById(effect.to)
            local num = 2
            if effect.extra_data and effect.extra_data.ysch4_tongdu then
                num = num + effect.extra_data.ysch4_tongdu
            end
            room:askForGuanxing(to, room:getNCards(num), nil, nil)
            room:drawCards(to, 2, self.name)
        end
    }
    tongdu_foresightSkill.cardSkill = true
    Fk:addSkill(tongdu_foresightSkill)
    local tongdu = fk.CreateTriggerSkill{
        name = "ysch4_tongdu",
        events = {fk.TurnEnd},
        can_trigger = function (self, event, target, player, data)
            local num = player:getMark("@ysch4_tongdu-round")
            return player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryRound) < (1 + num)
        end,
        times = function(self)
            return Self:getMark("@ysch4_tongdu-round") > 0 and (1+Self:getMark("@ysch4_tongdu-round")) - Self:usedSkillTimes(self.name, Player.HistoryPhase) or -1
        end,
        on_cost = function (self, event, target, player, data)
            local room = player.room
            local phase_judge, phase_play, phase_discard = {}, {}, {}
            room.logic:getEventsOfScope(GameEvent.Phase, 1, function (e)
                if e.data[1] == target then
                    if e.data[2] == Player.Judge then
                        table.insert(phase_judge, {e.id, e.end_id})
                    elseif e.data[2] == Player.Play then
                        table.insert(phase_play, {e.id, e.end_id})
                    elseif e.data[2] == Player.Discard then
                        table.insert(phase_discard, {e.id, e.end_id})
                    end
                end
            end, Player.HistoryTurn)
            local n = 0
            if #phase_judge > 0 then
                if #room.logic:getEventsOfScope(GameEvent.Judge, 1, function (e)
                    if table.find(phase_judge, function (info)
                        return e.id >= info[1] and e.id <= info[2]
                    end) then
                        local judge = e.data[1]
                        return judge.who == target and Fk.all_card_types[judge.reason] ~= nil
                    end
                end, Player.HistoryTurn) > 0 then
                    n = n + 1
                end
            end
            if #phase_play > 0 then
                if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
                    if table.find(phase_play, function (info)
                        return e.id >= info[1] and e.id <= info[2]
                    end) then
                        for _, move in ipairs(e.data) do
                            if move.toArea == Card.PlayerHand and move.to == target.id then
                                return true
                            end
                        end
                    end
                end, Player.HistoryTurn) > 0 then
                    n = n + 1
                end
            end
            if #phase_discard > 0 then
                if #room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function (e)
                    if table.find(phase_discard, function (info)
                        return e.id >= info[1] and e.id <= info[2]
                    end) then
                        for _, move in ipairs(e.data) do
                            if move.from == target.id and move.moveReason == fk.ReasonDiscard then
                                return true
                            end
                        end
                    end
                end, Player.HistoryTurn) == 0 then
                    n = n + 1
                end
            end

            if room:askForSkillInvoke(player,self.name,nil,"#ysch4_tongdu-prompt:::"..n) then
                self.cost_data = n
                return true
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            --room:useVirtualCard("foresight", nil, player, {player}, self.name)
            local card = Fk:cloneCard("ysch_Al__foresight")
            card.skillName = self.name
            local use = {from = player.id, card = card, tos = {{player.id}}, extra_data = {ysch4_tongdu = self.cost_data}}
            room:useCard(use)
        end,

        refresh_events = {fk.PreCardEffect},
        can_refresh = function (self, event, target, player, data)
            return table.contains(data.card.skillNames, self.name)
        end,
        on_refresh = function (self, event, target, player, data)
            local card = data.card:clone()
            local c = table.simpleClone(data.card)
            for k, v in pairs(c) do
            card[k] = v
            end
            card.skill = tongdu_foresightSkill
            data.card = card
        end,
    }
    liuba:addSkill(tongdu)
end
Fk:loadTranslationTable{
    ["ysch4_zhubi"] = "铸币",
    [":ysch4_zhubi"] = "出牌阶段，你可以重铸任意张点数和为4、8或12的牌。你本回合重铸的牌数每大于上述的一个数字，本轮“统度”可发动次数便+1。",
    ["#ysch4_zhubi"] = "铸币：你可以重铸任意张点数和为4、8或12的牌",
    ["@ysch4_zhubi-turn"] = "铸币",
    ["ysch4_tongdu"] = "统度",
    [":ysch4_tongdu"] = "每轮限一次，一名角色的回合结束时，你可以视为使用【洞烛先机】，其每满足下列一项，卜算牌数便+1：判定阶段判定过；出牌阶段获得过牌；弃牌阶段未弃置过牌。",
    ["@ysch4_tongdu-round"] = "统度 +",
    ["#ysch4_tongdu-prompt"] = "是否发动 统度，视为使用卜算牌数 + %arg 的【洞烛先机】",
}
local alaifu = General:new(extension, "ysch4__alaifu", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__alaifu"] = "阿莱夫",
    ["#ysch4__alaifu"] = "无限议题",
    ["designer:ysch4__alaifu"] = "草方块",
    ["cv:ysch4__alaifu"] = "重返未来1999",
    ["illustrator:ysch4__alaifu"] = "未知",
}
if alaifu then
    local quanliguixun = fk.CreateTriggerSkill{
        name = "ysch4_quanliguixun",
        events = {fk.TurnStart},
        anim_type = "control",
        can_trigger = function (self, event, target, player, data)
            return player:hasSkill(self.name) and player:usedSkillTimes(self.name,Player.HistoryRound) == 0 and target:getHandcardNum() > 1 and target ~= player
        end,
        on_cost = function (self, event, target, player, data)
            if player.room:askForSkillInvoke(player,self.name,nil,"#ysch4_quanliguixun-invoke::"..target.id) then
                return true
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local cp = target
            local colors = {}
            for _, id in ipairs(cp.player_cards[Player.Hand]) do
                if Fk:getCardById(id).color ~= Card.NoColor then
                    table.insertIfNeed(colors, Fk:getCardById(id):getColorString())
                end
            end
            if #colors > 1 then
                local color = room:askForChoice(cp, colors, self.name, "#ysch4_quanliguixun1")
                room:throwCard(table.filter(cp:getCardIds("h"),function (id)
                    return Fk:getCardById(id):getColorString() ~= color
                end), self.name, cp, cp)
            end
            if #cp.player_cards[Player.Hand] == 1 then cp = player end

            local types = {}
            for _, id in ipairs(cp.player_cards[Player.Hand]) do
                table.insertIfNeed(types, Fk:getCardById(id):getTypeString())
            end
            if #types > 1 then
                local type = room:askForChoice(cp, types, self.name, "#ysch4_quanliguixun2")
                room:throwCard(table.filter(cp:getCardIds("h"),function (id)
                    return Fk:getCardById(id):getTypeString() ~= type
                end), self.name, cp, cp)
            end
            if #cp.player_cards[Player.Hand] == 1 then cp = player end

            if #cp.player_cards[Player.Hand] > 1 then
                local ids = room:askForCard(cp,1,1,false,self.name,false,".","#ysch4_quanliguixun3")
                room:throwCard(table.filter(cp:getCardIds("h"),function (id)
                    return id ~= ids[1]
                end), self.name, cp, cp)
            end
        end,
    }
    alaifu:addSkill(quanliguixun)
    local lixiangxuanyan = fk.CreateTriggerSkill{
        name = "ysch4_lixiangxuanyan",
        events = {fk.BeforeCardsMove},
        can_trigger = function (self, event, target, player, data)
            if player:hasSkill(self.name) and player ~= player.room.current then
                for _, move in ipairs(data) do
                    if move.from == player.id and move.moveReason == fk.ReasonUse then
                        local use = player.room.logic:getCurrentEvent():findParent(GameEvent.UseCard,true).data[1]
                        if use.card.type ~= Card.TypeEquip and use.card.sub_type ~= Card.SubtypeDelayedTrick then
                            for _,info in ipairs(move.moveInfo) do
                                if info.fromArea == Card.PlayerHand then
                                    return true
                                end
                            end
                        end
                    end
                end
            end
        end,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local shows = {}
            for _, move in ipairs(data) do
                if move.moveReason == fk.ReasonUse then
                    for _, info in ipairs(move.moveInfo) do
                        table.insert(shows,info.cardId)
                    end
                    move.moveInfo = {}
                end
            end
            room:showCards(shows,player)
            local current = room.current
            if current and not current.dead then
                local choice = room:askForChoice(current,{"#ysch4_lixiangxuanyan1","#ysch4_lixiangxuanyan2"},self.name,"#ysch4_lixiangxuanyan-prompt::"..player.id..":"..table.concat(table.map(shows,function(id)
                    return Fk:getCardById(id):toLogString()
                end),"、"))
                if choice == "#ysch4_lixiangxuanyan1" then
                    room:throwCard(shows,self.name,player,current)
                else
                    room:throwCard(table.filter(player:getCardIds("h"),function (id)
                        return not table.contains(shows,id) 
                    end), self.name, player, current)
                end
            end
        end,
    }
    alaifu:addSkill(lixiangxuanyan)
end
Fk:loadTranslationTable{
    ["ysch4_quanliguixun"] = "权利规训",
    [":ysch4_quanliguixun"] = "每轮限一次，手牌数大于1的其他角色回合开始时，你可令其依次：1.仅保留一种颜色的手牌; 2.仅保留一种类型的手牌; 3.仅保留一张手牌。当其的手牌数变为1时，未执行项均由你执行。",
    ["#ysch4_quanliguixun-invoke"] = "是否发动 权利规训，令 %dest 按规则保留牌",
    ["#ysch4_quanliguixun1"] = "权利规训：保留一种颜色的手牌",
    ["#ysch4_quanliguixun2"] = "权利规训：保留一种类型的手牌",
    ["#ysch4_quanliguixun3"] = "权利规训：保留一张手牌",
    ["ysch4_lixiangxuanyan"] = "理想宣言",
    [":ysch4_lixiangxuanyan"] = "回合外，你可以以展示的方式使用牌。然后当前回合角色选择一项: 1.弃置展示牌; 2.弃置你所有未展示手牌。",
    ["#ysch4_lixiangxuanyan1"] = "弃置其展示牌",
    ["#ysch4_lixiangxuanyan2"] = "弃置其非展示手牌",
    ["#ysch4_lixiangxuanyan-prompt"] = "理想宣言：%dest 展示了 %arg，请选择一项",

    ["$ysch4_quanliguixun1"] = "我们只需要搭建起权力物理学。",
    ["$ysch4_quanliguixun2"] = "We need simply rely on the microphysics of power.",
    ["$ysch4_quanliguixun3"] = "多种多样的力量。",
    ["$ysch4_quanliguixun4"] = "All forms of power at your fingertips.",
    ["$ysch4_lixiangxuanyan1"] = "一场美妙的梦境！",
    ["$ysch4_lixiangxuanyan2"] = "A wonderful dream!",
    ["$ysch4_lixiangxuanyan3"] = "一则命运的馈赠！",
    ["$ysch4_lixiangxuanyan4"] = "A blessing bestowed by fate!",
    ["~ysch4__alaifu"] = "够了……够了……这一切都徒劳无益，只是谵妄命运的嘲弄……",
}
local Seiya = General:new(extension, "ysch4__Seiya", "west", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["ysch4__Seiya"] = "龙宫院圣哉",
    ["#ysch4__Seiya"] = "慎重勇者",
    ["designer:ysch4__Seiya"] = "伶",
    ["cv:ysch4__Seiya"] = "这个勇者明明超强却过分慎重",
    ["illustrator:ysch4__Seiya"] = "土日月",
}
if Seiya then
    local guofenshenzhong = fk.CreateActiveSkill{
        name = "ysch4_guofenshenzhong",
        anim_type = "drawcard",
        prompt = "#ysch4_guofenshenzhong-active",
        card_num = 2,
        target_num = 0,
        can_use = Util.TrueFunc,
        card_filter = function(self, to_select, selected)
            return #selected < 2 and not Self:prohibitDiscard(Fk:getCardById(to_select))
        end,
        on_use = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            room:throwCard(effect.cards, self.name, player, player)
            if not player.dead then
            player:drawCards(1, self.name)
            end
        end
    }
    local guofenshenzhong_maxcards = fk.CreateMaxCardsSkill{
        name = "#ysch4_guofenshenzhong_maxcards",
        main_skill = guofenshenzhong,
        fixed_func = function(self, player)
            if player:hasShownSkill(guofenshenzhong) and player.phase == Player.Discard then
                return 5
            end
        end
    }
    guofenshenzhong:addRelatedSkill(guofenshenzhong_maxcards)
    local guofenshenzhong_trigger = fk.CreateTriggerSkill{
        name = "#ysch4_guofenshenzhong_trigger",
        anim_type = "drawcard",
        frequency = Skill.Compulsory,
        events = {fk.DrawNCards},
        main_skill = guofenshenzhong,
        can_trigger = function (self, event, target, player, data)
            return target == player and player:hasSkill(guofenshenzhong.name)
        end,
        mute = true,
        on_use = function(self, event, target, player, data)
            player.room:notifySkillInvoked(player,"ysch4_guofenshenzhong","drawcard")
            data.n = data.n + 4
        end,

        refresh_events = {fk.CardUsing},
        can_refresh = function (self, event, target, player, data)
            return target == player and player:hasSkill(guofenshenzhong.name) and player.phase == Player.Play and (data.card.sub_type ~= Card.SubtypeArmor and data.card.trueName ~= "peach")
        end,
        on_refresh = function (self, event, target, player, data)
            player.room:addPlayerMark(player, "ysch4_guofenshenzhong-phase", 1)
        end,
    }
    guofenshenzhong:addRelatedSkill(guofenshenzhong_trigger)
    local guofenshenzhong_prohibit = fk.CreateProhibitSkill{
        name = "#ysch4_guofenshenzhong_prohibit",
        main_skill = guofenshenzhong,
        prohibit_use = function(self, player, card)
            if player:hasSkill(guofenshenzhong.name) and player.phase == Player.Play and player:getMark("ysch4_guofenshenzhong-phase") >= 3
            and card and (card.sub_type ~= Card.SubtypeArmor and card.trueName ~= "peach") then
                local subcards = card:isVirtual() and card.subcards or {card.id}
                return #subcards > 0 and table.every(subcards, function(id)
                return table.contains(player:getCardIds(Player.Hand), id)
                end)
            end
        end,
    }
    guofenshenzhong:addRelatedSkill(guofenshenzhong_prohibit)
    Seiya:addSkill(guofenshenzhong)
    local fangzhifuhuo = fk.CreateTriggerSkill{
        name = "ysch4_fangzhifuhuo",
        anim_type = "offensive",
        events = {fk.EnterDying},
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self.name) and target ~= player and not player:isKongcheng()
        end,
        mute = true,
        on_cost = Util.TrueFunc,
        on_use = function (self, event, target, player, data)
            local room = player.room
            local useS = {}
            local num = 0
            while true do
                local cardNames = {}
                local selfCards = {"peach", "analeptic", "ex_nihilo", "lightning"} -- FIXME: how to tell ex_niholo from AOE and AG?
                for _, id in ipairs(player:getCardIds(Player.Hand)) do
                    local card = Fk:getCardById(id)
                    if card.skill:modTargetFilter(target.id, {}, player, card, true) and not table.contains(selfCards, card.name) and card.type == Card.TypeTrick then -- FIXME
                        table.insert(cardNames, card.name)
                    end
                    if card.trueName == "slash" then
                        table.insert(cardNames, card.name)
                    end
                end
                local use = room:askForUseCard(player, "", table.concat(cardNames, ","), "#ysch4_fangzhifuhuo-use::"..target.id, true, {exclusive_targets = {target.id}, bypass_times = true, bypass_distances = true })
                if use then
                    num = num + 1
                    if num == 1 then
                        room:notifySkillInvoked(player,self.name,"offensive")
                    end
                    room:moveCardTo(use.card, Card.Processing, nil, fk.ReasonUse)
                    table.insert(useS,{player.id,{{target.id}},use.card.id})
                else
                    break
                end
            end
            p(useS)
            if num > 0 then
                room:setPlayerMark(player,"ysch4_fangzhifuhuo_target",target.id)
                room:setPlayerMark(player,"ysch4_fangzhifuhuo_use",useS)
            end
        end,

        refresh_events = {fk.AfterDying,fk.Death},
        can_refresh = function (self, event, target, player, data)
            return target.id == player:getMark("ysch4_fangzhifuhuo_target") and #player:getTableMark("ysch4_fangzhifuhuo_use") > 0
        end,
        on_refresh = function (self, event, target, player, data)
            local room = player.room
            for _, use in ipairs(player:getTableMark("ysch4_fangzhifuhuo_use")) do
                if event == fk.Death or target.dead then
                    room:moveCards{
                        fromArea = Card.Processing,
                        toArea = Card.DiscardPile,
                        ids = {use[3]},
                        moveReason = fk.ReasonUse,
                    }
                else
                    if not target.dead then
                        room:useCard({
                            from = use[1],
                            tos = use[2],
                            card = Fk:getCardById(use[3])
                        })
                    end
                end
            end
            room:setPlayerMark(player,"ysch4_fangzhifuhuo",0)
            room:setPlayerMark(player,"ysch4_fangzhifuhuo_target",0)
        end,
    }
    Seiya:addSkill(fangzhifuhuo)
end
Fk:loadTranslationTable{
    ["ysch4_guofenshenzhong"] = "明明超强却过分慎重",
    [":ysch4_guofenshenzhong"] = "锁定技，弃牌阶段，你的手牌上限视为5。摸牌阶段，你多摸四张牌。出牌阶段，你至多使用三张牌（防具牌和【桃】除外），且你能弃置两张牌并摸一张牌。",
    ["#ysch4_guofenshenzhong-active"] = "发动 明明超强却过分谨慎，选择要弃置的两张牌",
    ["ysch4_fangzhifuhuo"] = "防止复活",
    [":ysch4_fangzhifuhuo"] = "其他角色进入濒死状态时，你可以对其使用任意张【杀】或锦囊牌，其脱离濒死状态后依次结算。<br><br><font color='#a40000'>“太好了，这次终于拯救你了。”</font>",
    ["#ysch4_fangzhifuhuo-use"] = "防止复活：你可以对%dest使用一张牌，其脱离濒死状态后依次结算",
}
local leyi = General:new(extension, "ysch4__leyi", "yan", 4, 4, General.Male)--
Fk:loadTranslationTable{
    ["yan"] = "燕",
    ["ysch4__leyi"] = "乐毅",
    ["#ysch4__leyi"] = "悬旌断流",
    ["designer:ysch4__leyi"] = "楚萱",
    ["cv:ysch4__leyi"] = "",
    ["illustrator:ysch4__leyi"] = "",
}
if leyi then
    local lianke = fk.CreateViewAsSkill{
        name = "ysch4_lianke",
        pattern = "fire_attack,ysch_Al__unexpectation,ysch_Al__enemy_at_the_gates",
        interaction = function()
            local all_names = {"fire_attack", "ysch_Al__unexpectation", "ysch_Al__enemy_at_the_gates"}
            local names = U.getViewAsCardNames(Self, "ysch4_lianke", all_names)
            if #names > 0 then
                return U.CardNameBox { choices = names, all_choices = all_names }
            end
        end,
        view_as = function (self, cards, player)
            if #cards ~= 1 or not self.interaction.data then return end
            local card = Fk:cloneCard(self.interaction.data)
            card:addSubcards(cards)
            card.skillName = self.name
            return card
        end,
        card_filter = function(self, to_select, selected)
            return #selected == 0
        end,
        enabled_at_play = function(self, player)
            return player.phase == Player.Play and player:usedSkillTimes(self.name,Player.HistoryPhase) == 0
        end,
        enabled_at_response = function (self, player, response)
            return false
        end,
    }
    local lianke__fireAttackSkill = fk.CreateActiveSkill{
        name = "ysch4_lianke__fire_attack_skill",
        prompt = "#fire_attack_skill",
        target_num = 1,
        mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
            return not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
        end,
        target_filter = function(self, to_select, selected, selected_cards, card, _, player)
            if #selected < self:getMaxTargetNum(player, card) then
            return self:modTargetFilter(to_select, selected, player, card)
            end
        end,
        on_effect = function(self, room, cardEffectEvent)
            local from = room:getPlayerById(cardEffectEvent.from)
            local to = room:getPlayerById(cardEffectEvent.to)
            if to:isKongcheng() then return end

            local showCard = room:askForCard(to, 1, 1, false, "fire_attack_skill", false, ".|.|.|hand", "#fire_attack-show:" .. from.id)[1]
            local suit = Fk:getCardById(showCard):getSuitString()
            local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
            if use_event then
                local use = use_event.data[1]
                use.extra_data = use.extra_data or {}
                use.extra_data.ysch4_lianke = use.extra_data.ysch4_lianke or {}
                table.insertIfNeed(use.extra_data.ysch4_lianke, showCard)
            end
            to:showCards(showCard)

            if from.dead then return end

            local cards = room:askForDiscard(from, 1, 1, false, "fire_attack_skill", true,
            ".|.|" .. suit, "#fire_attack-discard:" .. to.id .. "::" .. suit, false)
            if #cards > 0 then
            room:damage({
                from = from,
                to = to,
                card = cardEffectEvent.card,
                damage = 1,
                damageType = fk.FireDamage,
                skillName = self.name,
            })
            end
        end,
    }
    lianke__fireAttackSkill.cardSkill = true
    Fk:addSkill(lianke__fireAttackSkill)
    local lianke__unexpectationSkill = fk.CreateActiveSkill{
        name = "ysch4_lianke__unexpectation_skill",
        can_use = Util.CanUse,
        target_num = 1,
        mod_target_filter = function(self, to_select, selected, player, card, distance_limited)
        return to_select ~= player.id and not Fk:currentRoom():getPlayerById(to_select):isKongcheng()
        end,
        target_filter = Util.TargetFilter,
        on_effect = function(self, room, effect)
            local player = room:getPlayerById(effect.from)
            local target = room:getPlayerById(effect.to)
            if target:isKongcheng() then return end
            local id = room:askForCardChosen(player, target, "h", "ysch_Al__unexpectation_skill")
            local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
            if use_event then
                local use = use_event.data[1]
                use.extra_data = use.extra_data or {}
                use.extra_data.ysch4_lianke = use.extra_data.ysch4_lianke or {}
                table.insertIfNeed(use.extra_data.ysch4_lianke, id)
            end
            target:showCards(id)
            local card = Fk:getCardById(id)
            if target.dead or card.suit == Card.NoSuit or effect.card.suit == Card.NoSuit then return end
            if card.suit ~= effect.card.suit then
                room:damage({
                from = player,
                to = target,
                card = effect.card,
                damage = 1,
                skillName = "ysch_Al__unexpectation_skill"
                })
            end
        end,
    }
    lianke__unexpectationSkill.cardSkill = true
    Fk:addSkill(lianke__unexpectationSkill)
    local lianke__enemyAtTheGatesSkill = fk.CreateActiveSkill{
        name = "ysch4_lianke__enemy_at_the_gates_skill",
        prompt = "#ysch_Al__enemy_at_the_gates_skill",
        can_use = Util.CanUse,
        target_num = 1,
        mod_target_filter = function(self, to_select, selected, user, card)
            return user.id ~= to_select
        end,
        target_filter = Util.TargetFilter,
        on_effect = function(self, room, cardEffectEvent)
            local player = room:getPlayerById(cardEffectEvent.from)
            local to = room:getPlayerById(cardEffectEvent.to)
            local cards = room:getNCards(4)
            local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
            if use_event then
                local use = use_event.data[1]
                use.extra_data = use.extra_data or {}
                use.extra_data.ysch4_lianke = use.extra_data.ysch4_lianke or {}
                table.insertIfNeed(use.extra_data.ysch4_lianke, cards)
            end
            room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
            for _, id in ipairs(cards) do
                local card = Fk:getCardById(id)
                if card.trueName == "slash" and not player:prohibitUse(card) and not player:isProhibited(to, card) and to:isAlive() then
                    if use_event then
                        local use = use_event.data[1]
                        use.extra_data = use.extra_data or {}
                        use.extra_data.useSha = use.extra_data.useSha or {}
                        table.insertIfNeed(use.extra_data.useSha, id)
                    end
                    card.skillName = self.name
                    room:useCard({
                        card = card,
                        from = player.id,
                        tos = { {to.id} },
                        extraUse = true,
                    })
                end
            end
            room:cleanProcessingArea(cards, self.name)
        end,
    }
    lianke__enemyAtTheGatesSkill.cardSkill = true
    Fk:addSkill(lianke__enemyAtTheGatesSkill)
    local lianke_trigger = fk.CreateTriggerSkill{
        name = "#ysch4_lianke_trigger",
        refresh_events = {fk.PreCardEffect,fk.Damage},
        can_refresh = function (self, event, target, player, data)
            if event == fk.PreCardEffect then
                return data.from == player.id and table.contains(data.card.skillNames, "ysch4_lianke")
            else
                return target == player and data.card and table.contains(data.card.skillNames, "ysch4_lianke")
            end
        end,
        on_refresh = function (self, event, target, player, data)
            if event == fk.PreCardEffect then
                local card = data.card:clone()
                local c = table.simpleClone(data.card)
                for k, v in pairs(c) do
                    card[k] = v
                end
                if data.card.trueName == "fire_attack" then
                    card.skill = lianke__fireAttackSkill
                elseif data.card.trueName == "unexpectation" then
                    card.skill = lianke__unexpectationSkill
                else
                    card.skill = lianke__enemyAtTheGatesSkill
                end
                data.card = card
            else
                local room = player.room
                local showCards = {}
                local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
                if use_event then
                    local use = use_event.data[1]
                    use.extra_data = use.extra_data or {}
                    showCards = use.extra_data.ysch4_lianke or {}
                end

                local name = "fire_attack"
                if data.card.trueName == "fire_attack" then
                    name = "ysch_Al__unexpectation"
                elseif data.card.trueName == "unexpectation" then
                    name = "ysch_Al__enemy_at_the_gates"
                end
                local success, dat =  room:askForUseViewAsSkill(player,"#ysch4_lianke_viewas","#ysch4_lianke_use:::"..name,true,{ysch4_lianke = name})
                if success then
                    local cards = showCards
                    if #dat.cards > 0 then
                        cards = dat.cards
                        room:moveCardTo(table.reverse(showCards), Card.DrawPile, nil, fk.ReasonPut, self.name, nil, true, player.id)
                    end
                    local card = Fk:cloneCard(name)
                    card:addSubcards(cards)
                    card.skillName = "ysch4_lianke"
                    room:useCard({from = player.id, tos = table.map(dat.targets, function(id) return {id} end), card = card})
                end
            end
        end,
    }
    lianke:addRelatedSkill(lianke_trigger)
    leyi:addSkill(lianke)
    local lianke_viewas = fk.CreateViewAsSkill{
        name = "#ysch4_lianke_viewas",
        max_card_num = 1,
        min_card_num = 0,
        handly_pile = true,
        card_filter = function(self, to_select, selected)
            return #selected == 0
        end,
        view_as = function(self, cards)
            if not self.ysch4_lianke then return end
            local card = Fk:cloneCard(self.ysch4_lianke)
            if #cards > 0 then
                card:addSubcard(cards[1])
            end
            card.skillName = "ysch4_lianke"
            return card
        end,
    }
    Fk:addSkill(lianke_viewas)
end
Fk:loadTranslationTable{
    ["ysch4_lianke"] = "连克",
    [":ysch4_lianke"] = "出牌阶段限一次，你可以将一张牌当【火攻】、【出其不意】或【兵临城下】使用。你的“连克”牌造成伤害后，你可以选择一项：1.将被展示的牌当下一张牌使用；2.将被展示的牌置于牌堆顶，再将一张牌当下一张牌使用。",
    ["#ysch4_lianke_use"] = "连克：你可以将展示牌置于牌堆顶并将一张牌当【%arg】使用；或不选牌，直接将展示牌当之使用",
}
return extension--